在oracle的plsql中为cursor使用绑定变量
时间:2010-09-09 来源:cnhtm
oracle存储过程中,经常使用cursor,在cursor中使用绑定变量的时候,要使用refcursor,下面是例子:
scott@CNHTM> set serveroutput on; scott@CNHTM> declare 2 cur_test sys_refcursor; 3 v_job emp.job%type; 4 v_ename emp.ename%type; 5 begin 6 OPEN cur_test FOR 'SELECT job,ename FROM emp where job=:1' 7 using 'SALESMAN'; 8 loop 9 fetch cur_test 10 into v_job, v_ename; 11 exit when cur_test%notfound; 12 dbms_output.put_line('job:'||v_job||', ename:'||v_ename); 13 end loop; 14 close cur_test; 15 end; 16 / job:SALESMAN, ename:ALLEN job:SALESMAN, ename:WARD job:SALESMAN, ename:MARTIN job:SALESMAN, ename:TURNER PL/SQL procedure successfully completed. scott@CNHTM> |
--end--
相关阅读 更多 +