2016-11-19 2 views
0

Wenn ich diesen Code ausführen, sollte das Ergebnis 636790 aber 63679 wird nur zurückgegeben. Schlagen Gehirne auf diesem einen !!! Warum die fehlende Ziffer? Quelltabelle und Spalte enthalten richtige Anzahl von 636790.Oracle PL/SQL Ref Cursor Funktion fehlt Char

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; 
+0

Warum ich denke, dass 'jt_types.ttest' etwas wie 'char (6)'? –

Antwort

0

Der einfachste Weg ist zu tun sys_refcursor zurückzukehren, hier ist der Code:

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;