Solved

:OLD and :NEW values in PL/SQL

Posted on 2009-04-13
2
540 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

809 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