|
|
|
|
Re: Returning updated rows with REF CURSOR? [message #596974 is a reply to message #596929] |
Sat, 28 September 2013 07:15 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
You can't do this with cursor directly. What you can do is:
SQL> drop table emp1 purge
2 /
Table dropped.
SQL> create table emp1
2 as
3 select empno,
4 ename,
5 sal,
6 deptno
7 from emp
8 /
Table created.
SQL> set serveroutput on
SQL> declare
2 v_empno_tbl sys.OdciNumberList;
3 v_cur sys_refcursor;
4 v_rec emp1%rowtype;
5 begin
6 update emp1
7 set sal = sal + 1000
8 where deptno = 10
9 returning empno
10 bulk collect
11 into v_empno_tbl;
12 open v_cur
13 for
14 select *
15 from emp1
16 where empno in (select * from table(v_empno_tbl));
17 loop
18 fetch v_cur
19 into v_rec;
20 exit when v_cur%notfound;
21 dbms_output.put_line(v_rec.ename || ' new salary is ' || v_rec.sal);
22 end loop;
23 close v_cur;
24 end;
25 /
CLARK new salary is 3450
KING new salary is 6000
MILLER new salary is 2300
PL/SQL procedure successfully completed.
SQL>
Keep in mind, it isn't 100% equivalent to your "code". If returning clause would allow cursor, such cursor would be read consistent to "right after update" point-in-time, while in code I posted there is a gap. So if some other session committed changes to table emp1 updated rows (deptno = 10) within that gap, select in code I posted will see such changes.
SY.
|
|
|