【问题标题】:How can I explore an out cursor parameter in a PLSQL block?如何探索 PLSQL 块中的 out 游标参数?
【发布时间】:2012-06-13 16:27:50
【问题描述】:

我需要验证一个具有 out 游标参数的过程。具体来说,我需要查看正在检索的内容。

我试试这个:

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;

错误是“cur”没有被定义。

【问题讨论】:

    标签: parameters plsql cursor out


    【解决方案1】:

    您不能将光标 FOR 循环与 ref 光标一起使用,您必须这样做:

    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;
    

    注意:不再需要定义自己的引用游标类型(除非您使用的是非常旧的 Oracle 版本)。您可以只使用 SYS_REFCURSOR:

    declare
      cur sys_refcursor; 
      ...
    

    【讨论】:

    • 太棒了,我搜索了很多,我找不到任何东西,你节省了我一天的工作:D
    猜你喜欢
    • 1970-01-01
    • 2012-08-08
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    相关资源
    最近更新 更多