Solved

:OLD and :NEW values in PL/SQL

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.

696 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