Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

:OLD and :NEW values in PL/SQL

Posted on 2009-04-13
2
Medium Priority
?
555 Views
Last Modified: 2013-12-18
Hi... I saw some lines in pl/sql, that were using this sintax below:

(in the first line it has REFERENCING NEW AS NEW AND OLD AS OLD)

and then:
 
BLQ_CDEMPRESA = :OLD.LCT_CDEMPRES

So, what this sintax means? What means the column name and old.column_name?
0
Comment
Question by:Thiago_corporative
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 2000 total points
ID: 24132733
Hope you have provided the Trigger code above.
In a trigger, You have two states of data one before the code is executed and the other after the code is executed.
Earlier is called as OLD value and the later is called as :NEW value.

To initiate that , NEW AS NEW AND OLD AS OLD
Below is the syntax of a trigger.

Hope that clarifies.
CREATE [OR REPLACE] TRIGGER <trigger_name>
    {BEFORE|AFTER} {INSERT|DELETE|UPDATE} ON <table_name>
    [REFERENCING [NEW AS <new_row_name>] [OLD AS <old_row_name>]]
    [FOR EACH ROW [WHEN (<trigger_condition>)]]
    <trigger_body>

Open in new window

0
 
LVL 4

Expert Comment

by:Cakinci
ID: 24132825
It is a propoerty in Pl/SQL that you can create a trigger that works on both new values and old values (In update trigger for example)

You can use this property to create a log file of changes(or table),auidit the changes or just output purposes.

Let me give you a simple example of code:
When you try to update id field in below table it will output such text:
update employee set id='01' where id='02';
:new.id: 01
:old.id: 02


I hope this will help.

 create table Employee(
      ID                 VARCHAR2(4 BYTE)         NOT NULL
  )
 
 
-- BEFORE UPDATE Trigger
CREATE OR REPLACE TRIGGER employee_before_update
     BEFORE UPDATE
         ON employee
         FOR EACH ROW
      
      BEGIN
      dbms_output.put_line(':new.id: '||:new.id);
      dbms_output.put_line(':old.id: '||:old.id);
 
      END;

Open in new window

0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question