在oracle的plsql中為cursor使用繫結變數

cnhtm發表於2010-09-09

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--

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22049049/viewspace-1038105/,如需轉載,請註明出處,否則將追究法律責任。

相關文章