请问如何用一条select语句select出一个cursor ref的记录?那个cursor ref是从function中返回的.

解决方案 »

  1.   

    -- 定义游标 
    declare 
    cursor aa is 
    select names,num,to_char(sysdate,'YYYY-MM-DD') DATE from test; 使用函数和上面的to_char函数道理是一样的
      

  2.   

    to hdhai9451 :
    在select中直接select游标只能显示cursor对象,不知道有没有展开cursor对象的方法..SELECT pkg_test.get() c FROM dual结果:
    <Cursor>to yf520gn :
    函数可以返回游标啊.
      

  3.   

    没有直接的select就可以展开的。你用plsql的话,select是一个游标,你可以像打开clob那样展开内容。
    或者使用程序块或过程来输出:给你个例子
    create or replace function fc return sys_refcursor as
    c sys_refcursor;
    begin
    open c for select * from emp;
    return c;
    end;
    declare
      emprow emp%rowtype;
      s      sys_refcursor;
    begin
      s := fc;
      loop
        fetch s
          into emprow;
        exit when s%notfound;
        dbms_output.put_line(emprow.ename);
      end loop;
      close s;
    end;
      

  4.   

    函数返回的是引用游标的类型
    你只能得到这个返回类型
    如果你可以定义一个函数来接收这个游标,你需要的功能貌似还可以实现
    declare
     c sys_refcursor;
    begin
    SELECT pkg_test.get() into c FROM dual ;
    end;
    但经过测试发现,这条路似乎是行不通的,因为你没有办法打开这个引用的游标。
      

  5.   

    啊~~~真没办法了~~~因为主要是想实现select * from table(pkg_test.get())的功能,所以不能用块去调用函数.并且函数中存在动态构建结构的语句,函数不能返回pipelined,否则就会报:ORA-14552 cannot perform a DDL, commit or rollback inside a query ...