Home » SQL & PL/SQL » SQL & PL/SQL » Variables (sql)
Variables [message #647663] Thu, 04 February 2016 16:49 Go to next message
M123
Messages: 47
Registered: February 2016
Location: USA
Member

Hi all

what are these variables new. and old ,are they automatically processed.
please check this link below
http://www.tutorialspoint.com/plsql/plsql_triggers.htm
OLD and NEW references are not available for table level triggers, rather you can use them for record level triggers. does plsql engine process new. and old. automatically ?

same here in below namedblock, i mentioned new. , does plsql internally considers it as new variable ?

create  or replace trigger crazy_trigge1r before update
     on employees
     for each row
   begin
      if :new.last_name = 'Pataballa' then
         :new.salary := :new.salary * 0.1;
        dbms_output.put_line('update done for the last name '||:new.last_name);
     end if;
end;


Please help in understanding this basic functionality ,what does that "new." do ,any comments

[EDITED by LF: fixed topic title typo and applied code tags]

[Updated on: Fri, 05 February 2016 00:05] by Moderator

Report message to a moderator

Re: varaibles [message #647664 is a reply to message #647663] Thu, 04 February 2016 18:04 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read

ALWAYS Read The Fin Manuals

https://docs.oracle.com/database/121/LNPLS/toc.htm

NEVER hesitate to use GOOGLE

https://www.google.com/webhp?hl=en&tab=ww#hl=en&q=oracle+trigger+new+old
Re: varaibles [message #647667 is a reply to message #647663] Thu, 04 February 2016 18:18 Go to previous messageGo to next message
M123
Messages: 47
Registered: February 2016
Location: USA
Member

CREATE OR replace TRIGGER crazy_trigge1r
    BEFORE UPDATE ON employees
   FOR EACH ROW
BEGIN
     IF :new.last_name = 'Pataballa' THEN
       :new.salary := :new.salary * 0.1;

        dbms_output.Put_line('update done for the last name '
                            ||:new.last_name);
      END IF; 
  END; 


i have gone through this link https://docs.oracle.com/cd/B10501_01/appdev.920/a96590/adg13trg.htm#431Because the trigger uses the BEFORE keyword, it can access the new values before they go into the table, and can change the values if there is an easily-corrected error by assigning to :NEW.column_name

so does it mean this block can automatically declares new varialbe "new." and update it ? can you suggest what does this :new. do ?

[Updated on: Thu, 04 February 2016 18:33]

Report message to a moderator

Re: varaibles [message #647668 is a reply to message #647667] Thu, 04 February 2016 18:52 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Let us use your example above about doing UPDATE of the EMPLOYEES table.
:NEW or :OLD allow you to specify whether to utilize the existing value in the column (:OLD) or the value to which the column is being SET (:NEW)

TRIGGER can be used to AUDIT table changes.
So then TRIGGER may place both the :OLD value & the :NEW value in the AUDIT record

https://docs.oracle.com/database/121/LNPLS/triggers.htm#sthref813
Re: varaibles [message #647669 is a reply to message #647668] Thu, 04 February 2016 19:17 Go to previous message
M123
Messages: 47
Registered: February 2016
Location: USA
Member

Thankyou.

for sharing this information, concept of correlation and pseudorecords.
will work on this again , and post any questions if any .

Smile
Previous Topic: change permanently the value of the initialization parameter
Next Topic: Need to convert into date for differernt kind of formates
Goto Forum:
  


Current Time: Thu Jun 25 16:55:19 CDT 2026