0

当我运行这段代码时,结果应该是 636790 但只返回 63679。在这一点上绞尽脑汁!!!为什么少了一个数字?源表和列包含正确的数字 636790。

create or replace package jt_types 
  as 
    type ttest is ref cursor;
end; 

CREATE OR REPLACE FUNCTION jt_test
      RETURN jt_types.ttest
   IS
       o_return  jt_types.ttest;   
   BEGIN
           OPEN o_return FOR
               SELECT offn_id
               FROM jt_offn_4
              where offn_ID in (636790)
            ORDER BY offn_id;
     RETURN o_return;
  END jt_test;  

DECLARE
     l_ids                  jt_types.ttest;
     l_id                   NUMBER;   
BEGIN
    l_ids := jt_test;   
  LOOP
          FETCH l_ids INTO l_id;
          EXIT WHEN l_ids%NOTFOUND;
          dbms_output.put_line('Rec: ' || l_id);
  END LOOP;
  CLOSE l_ids;
 END;
4

1 回答 1

0

最简单的方法是返回 sys_refcursor,代码如下:

create or replace 
function jt_test
      return sys_refcursor
   is
       o_return  sys_refcursor;   
   begin
           open o_return for
               select offn_id
               from jt_offn_4
              where offn_ID = 636790;
     return o_return;
  end jt_test;

declare
     l_ids                  sys_refcursor;
     l_id                   number;   
begin
  l_ids := jt_test;   
  loop
    fetch l_ids into l_id;
    dbms_output.put_line('Rec: ' || l_id);
    exit when l_ids%NOTFOUND;
  end loop;

  close l_ids;

 end;
于 2016-11-19T19:44:07.797 回答