程序中的sys_refcursor不返回数据

时间:2014-01-03 14:07:14

标签: oracle stored-procedures sys-refcursor

CREATE TYPE prList AS TABLE OF pr;

create or replace
procedure qLink(ret  out sys_refcursor)
 IS
myPrList prList := prList();


  open ret for
  select * 
  from (select a.lin, a.pr, 
               b.name, sum(a.up) as u,
               sum (a.d)         as d
          from li_dy_4 a,
               p_list  b,
               TABLE(CAST(myPrList as prList)) my_list
         where a.pr=b.id 
           and b.parent_id != 0 
           and a.partitionid <= 308 
           and a.partitionid >= 302 
           and a.pr = my_list.pr
         GROUP BY a.pr, b.name, a.lin  
         order by d desc) ;


BEGIN 

 myPrList := prList ( pr(91),
                   pr(80));


END;

  variable rc refcursor;
  exec qlink( :rc );
  print rc;

[/代码]

上面的示例代码没有返回任何数据,只显示表字段。我在这里想念什么? 但如果没有使用refcursor evry的东西工作正常,即使我尝试将数组作为列表传递它与上面的代码一起工作,请帮助......

1 个答案:

答案 0 :(得分:0)

我认为一定是这样的:

create or replace
procedure qLink(ret  out sys_refcursor)
 IS
myPrList prList := prList();

BEGIN 

 myPrList := prList ( pr(91),pr(80));

  open ret for
  select * 
  from (select a.lin, a.pr, 
               b.name, sum(a.up) as u,
               sum (a.d)         as d
          from li_dy_4 a,
               p_list  b,
               TABLE(CAST(myPrList as prList)) my_list
         where a.pr=b.id 
           and b.parent_id != 0 
           and a.partitionid <= 308 
           and a.partitionid >= 302 
           and a.pr = my_list.pr
         GROUP BY a.pr, b.name, a.lin  
         order by d desc) ;

END;

也许这个TABLE(CAST(myPrList as prList)) my_list可以简单地用这个代替:TABLE(prList(pr(91),pr(80))) my_list - 但我没有测试它!