Solved

:OLD and :NEW values in PL/SQL

Posted on 2009-04-13
2
538 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
2 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with Oracle syntax 4 56
T-SQL Convert to PL/SQL 23 77
query in Oracle forms Builder 2 41
Oracle - SQL Parse String 5 15
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now