declare
cursor c1(p_id int) is select * from t where id=p_id ;
begin
open c1( 1) ;
end;
---------------------------
create table hxz_01 (a int);
insert into hxz_01 values(1);
insert into hxz_01 values(2);
insert into hxz_01 values(2);
insert into hxz_01 values(3);
commit;
/
set serveroutput on
declare
cursor l_cursor(p int) is select * from hxz_01 where a = p;
l_tmp hxz_01%rowtype;
begin
open l_cursor(2);
loop
fetch l_cursor into l_tmp;
exit when l_cursor%notfound;
dbms_output.put_line(l_tmp.a);
end loop;
end;
/
--Ref cursor exampl
declare
type refcursor is ref cursor;
l_tmp hxz_01%rowtype;
l_cursor refcursor;
begin
open l_cursor for 'select * from hxz_01 where a = :p' using 2;
loop
fetch l_cursor into l_tmp;
exit when l_cursor%notfound;
dbms_output.put_line(l_tmp.a);
end loop;
end;
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/46907/viewspace-917145/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/46907/viewspace-917145/