2012-06-13 75 views
0

我需要验证一个具有out游标参数的过程。具体而言,我需要查看什么是检索。如何在PLSQL块中探索出游标参数?

我试试这个:

declare 
    type cursor_out is ref cursor; 
    cur cursor_out; 
    fila activ_economica%rowtype; 
    procedure test(algo out cursor_out) is 
    begin 
    open algo for select * from activ_economica; 
    end; 
begin 
    test(cur); 
    for i in cur loop 
    fila := i; 
    dbms_output.put(fila.id_activ_economica ||' '); 
    dbms_output.put_line(fila.nom_activ_economica); 
    end loop; 
end; 

的错误是 “小人” 一直没有被定义。

回答

2

不能使用游标FOR循环与裁判光标,你必须这样做:

declare 
    type cursor_out is ref cursor; 
    cur cursor_out; 
    fila activ_economica%rowtype; 
    procedure test(algo out cursor_out) is 
    begin 
    open algo for select * from activ_economica; 
    end; 
begin 
    test(cur); 
    loop 
    fetch cur into fila; 
    exit when cur%notfound; 
    dbms_output.put(fila.id_activ_economica ||' '); 
    dbms_output.put_line(fila.nom_activ_economica); 
    end loop; 
    close cur; 
end; 

注:不再有任何需要定义自己的REF游标类型(除非你是一个很老的Oracle版本)。你可以直接使用SYS_REFCURSOR:

declare 
    cur sys_refcursor; 
    ... 
+0

excelent,我搜索了很多,我找不到任何东西,你救了我一天的工作:D – mjsr