DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Accesing the new values of the column in an update statement

  1. #1
    Join Date
    Apr 2002
    Location
    Chennai
    Posts
    27

    Accesing the new values of the column in an update statement

    Hi,

    Is there a way to access the new value of an updated column in the same update statement, just like in triggers, which allows us with the :new and ld references.

    Srinivas.

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Use RETURNING clause of the UPDATE ststement. For example:
    Code:
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.1.1 - Production
    With the Partitioning option
    JServer Release 8.1.7.1.1 - Production
    
    SQL> set serveroutput on
    SQL> DECLARE
      2    v_sal NUMBER;
      3  BEGIN
      4    SELECT sal INTO v_sal FROM emp WHERE ename = 'KING'; 
      5    dbms_output.put_line('Salary before the update: ' || v_sal);
      6    UPDATE emp SET sal = sal*2 WHERE ename = 'KING'
      7      RETURNING sal INTO v_sal;
      8    dbms_output.put_line('Salary after the update: ' || v_sal);
      9  END;
     10  /
    Salary before the update: 8450
    Salary after the update: 16900
    
    PL/SQL procedure successfully completed.
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  3. #3
    Join Date
    Apr 2002
    Location
    Chennai
    Posts
    27
    Thanks jurij

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width