Passer un CURSOR en paramètre à une procédure
Bonjour,
Le titre est explicite, je souhaite passer un CURSOR en paramètre d'une procédure.
Je suis sous Oracle 10g.
J'ai écrit ce qui suit, mais j'ai un soucis de TYPE.
Quand je met "CURSOR" à la place de "SYS_REFCURSOR", ça ne marche pas non plus.
Le code en question :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| SET serveroutput ON
DECLARE
CURSOR INTERNAL_PATH_CURSOR IS
Select 1 as id from dual
union
Select 10 from dual
;
myId INTEGER;
PROCEDURE printRow( cur_lig IN SYS_REFCURSOR) IS
BEGIN
LOOP
FETCH cur_lig INTO myId ;
EXIT WHEN cur_lig%NOTFOUND ;
dbms_output.put_line( 'Found : ' || myId ) ;
END LOOP ;
End;
BEGIN
dbms_output.put_line( 'Trying procedure with cursor ...' ) ;
printRow(INTERNAL_PATH_CURSOR);
END;
/ |
Merci à vous pour votre aide.
Step by step comme on dit a Clermont-Ferrand
Faut pas tout essayer dans tous les sens. C'est tres clairement contre-productif. ;)
Premiere chose:
http://download.oracle.com/docs/cd/E...s.htm#CIHDFDJG
Lire la doc sur le PL/SQL ca ne peut que vous faire gagner du temps a moyen terme, limite court terme la.;)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| DECLARE
TYPE gencurtyp IS REF CURSOR;
-- Retrieve list of internel paths
INTERNAL_PATH_CURSOR gencurtyp;
myid INTEGER;
cur_text varchar2(200):='SELECT 3 FROM DUAL UNION SELECT 4 FROM DUAL';
procedure printRow(p_cursor IN gencurtyp) IS
begin
LOOP
FETCH p_cursor INTO myid;
exit when p_cursor%notfound;
dbms_output.put_line('myid = ' || myid);
END LOOP;
CLOSE p_cursor;
end;
BEGIN
open internal_path_cursor FOR SELECT 1 AS id FROM dual union SELECT 2 FROM dual;
printRow(INTERNAL_PATH_CURSOR);
open internal_path_cursor for cur_text;
printRow(INTERNAL_PATH_CURSOR);
END;
/ |
Votre boucle, elle est infinie.
Et enfin, DBMS_OUTPUT.PUT, il n'imprime rien a l'ecran. Il faut un PUT_LINE. Ca, faut l'avoir vu pour le savoir.:)