Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trigger question

Status
Not open for further replies.

mkey

Programmer
Oct 3, 2001
288
CA
Hi all,
Why we use REFERENCING in a trigger?
The following trigger contains the REFERENCING clause:

CREATE OR REPLACE TRIGGER C_BIR
BEFORE INSERT
ON schema.c_table
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
BEGIN
SELECT c_SEQ.NEXTVAL INTO :NEW.ID FROM DUAL;
END;
/

What does the "REFERENCING OLD AS OLD NEW AS NEW" means and why we need to use it?

Thanks!
 
By default :new and :eek:ld are used as record value BEFORE and AFTER statement execution. Though using REFERENCING clause you may use other words.

CREATE OR REPLACE TRIGGER C_BIR
BEFORE INSERT
ON schema.c_table
REFERENCING OLD AS FOO NEW AS BAR
FOR EACH ROW
BEGIN
IF :FOO.ID IS NULL THEN
SELECT c_SEQ.NEXTVAL INTO :BAR.ID FROM DUAL;
END IF;
END;

Regards, Dima
 
So in otherwords, the REFERENCING clause in your trigger is not needed since you are using the standard NEW and OLD (but it doesn't hurt anything either).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top