代码之家  ›  专栏  ›  技术社区  ›  Martin

如何检查ref游标是否从pl/sql过程返回数据

  •  2
  • Martin  · 技术社区  · 15 年前

    假设我在PL/SQL包中有以下代码:

    type refcursor is ref cursor;
    
    procedure Foo(cursorresult out refcursor) is
    begin
      open cursorresult for
        select *
          from table t
          inner join t2 on t.id = t2.id
         where t.column1 is null;
    end;
    
    procedure DoSomeghingIfFooHasResults is
      curFoo refcursor;
      begin
        Foo(curSansOwner);
        if curFoo%found then
          -- Do something
        end if;
    end function;
    

    此代码用于一个更复杂的进程,Foo中的查询使用多个表。

    我想在一些地方重用查询,但我不认为这是一个很好的视图候选。

    如果Foo发现了什么最好的方法是什么?

    谢谢。

    1 回复  |  直到 15 年前
        1
  •  5
  •   Tony Andrews    15 年前

    要知道它是否找到了什么,唯一的方法就是从中提取:

    procedure DoSomeghingIfFooHasResults is
      curFoo refcursor;
      recFoo mytable%ROWTYPE;
      begin
        Foo(curFoo);
        fetch curFoo into recFoo;
        if curFoo%found then
          -- Do something
        end if;
    end function;