2014-09-19 67 views
0

我在Oracle中創建一個存儲過程,是選擇從登錄表中的記錄 -存儲過程相關

create or replace procedure login_info 
    (username IN varchar2, password IN varchar2, result OUT number) 
as 
begin 
    select * from login; 
end; 

每當我要編譯該它顯示了一個錯誤:

PLS-00428: an INTO clause is expected in this SELECT statement

是什麼這個意思?我不明白。

回答

0

PLS-00428: an INTO clause is expected in this SELECT statement

這意味着你需要一個INTO接近,當你從PL/SQL發佈裸SELECT

:d


更有建設性:您認爲在您選擇的結果會去在該代碼片段?

create or replace procedure login_info 
    (username IN varchar2, password IN varchar2, result OUT number) 
as 
begin 
    select * from login; 
end; 

您必須以某種方式檢索它以便通過PL/SQL代碼進行處理。假設你有幾行收集,你應該使用BULK COLLECT INTO

create or replace procedure login_info 
    (username IN varchar2, password IN varchar2, result OUT number) 
as 
    type my_tbl_type IS TABLE OF login%ROWTYPE; 
    my_tbl my_tbl_type; 
begin 
    select * BULK COLLECT INTO my_tbl from login; 

    -- do whatever you 
    -- need here 
    -- on `my_tbl`. 
end; 

最後一點,也許你在找一個明確的CURSOR呢?你應該明確地看看PL/SQL 101: Working with Cursors。這是一個關於SELECT ... INTO ...CURSOR操作的有趣討論。

2

您必須將SELECT語句的結果存儲到一個變量中,您可以使用sys_refcursor來顯示結果。

create or replace procedure login_info 
    (username IN varchar2, password IN varchar2, result OUT number, result_out OUT SYS_REFCURSOR) 
as 
l_query varchar2(1000) := Null; 

begin 
    l_query := 'select * from login'; 
open result_out 
for l_query; 
end; 

上面的代碼將會給你輸出