Home » SQL & PL/SQL » SQL & PL/SQL » RETURNING in EXECUTE IMMEDIATE
RETURNING in EXECUTE IMMEDIATE [message #10026] Tue, 23 December 2003 01:35 Go to next message
resy
Messages: 86
Registered: December 2003
Member
hi,

just read the following code,

sql_stmt := 'UPDATE emp SET sal = 2000 WHERE empno = :1
RETURNING sal INTO :2';

EXECUTE IMMEDIATE sql_stmt USING emp_id RETURNING INTO salary;

here what does 'RETURNING' do?

thanx for all answers.
Re: RETURNING in EXECUTE IMMEDIATE [message #10027 is a reply to message #10026] Tue, 23 December 2003 02:54 Go to previous message
Art Metzer
Messages: 2480
Registered: December 2002
Senior Member
SQL> DECLARE
  2      sql_stmt        VARCHAR2(100);
  3      emp_id          emp.empno%TYPE := 7844;
  4      orig_salary     emp.sal%TYPE;
  5      salary          emp.sal%TYPE;
  6      new_salary      emp.sal%TYPE;
  7  BEGIN
  8      SELECT e.sal
  9      INTO   orig_salary
 10      FROM   emp       e
 11      WHERE  e.empno = emp_id;
 12
 13      DBMS_OUTPUT.PUT_LINE(emp_id || '''s original salary = ' || orig_salary);
 14      DBMS_OUTPUT.PUT_LINE('Value of ''salary'' variable before update = ' || salary);
 15
 16      sql_stmt := 'UPDATE emp SET sal = 2000 WHERE empno = :1 RETURNING sal INTO :2';
 17
 18      EXECUTE IMMEDIATE sql_stmt USING emp_id RETURNING INTO salary;
 19
 20      DBMS_OUTPUT.PUT_LINE('Value of ''salary'' variable after update = ' || salary);
 21
 22      SELECT e.sal
 23      INTO   new_salary
 24      FROM   emp       e
 25      WHERE  e.empno = emp_id;
 26
 27      DBMS_OUTPUT.PUT_LINE(emp_id || '''s salary now = ' || new_salary);
 28  END;
 29  /
7844's original salary = 1500
Value of 'salary' variable before update =
Value of 'salary' variable after update = 2000
7844's salary now = 2000
  
PL/SQL procedure successfully completed.
  
SQL>
See also this link to the documentation of the RETURNING INTO clause of EXECUTE IMMEDIATE.

Hope this helps,

Art.
Previous Topic: SQL PROBLEM!
Next Topic: PL/SQL Tables
Goto Forum:
  


Current Time: Fri Apr 19 16:24:13 CDT 2024