dbTalk Databases Forums  

Trigger deleting :new value

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Trigger deleting :new value in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Menthe&Basilic
 
Posts: n/a

Default Trigger deleting :new value - 11-06-2007 , 03:45 AM






Hello

I have an update trigger that is for each row.
The goal is to detect if a timestamp field is updated, if not updated
it with system timestamp.
My problem is the value of this field is lost and I end up with null
value in the table.
I am attaching my testing script
I am using Oracle 10g.

Thanks for your help.
CREATE OR REPLACE TRIGGER TU_FORWARD_FX_RATE_TS
BEFORE UPDATE ON FORWARD_FX_RATE_TS referencing new as new, old as
old
FOR EACH ROW
--WHEN (new.last_modified_timestamp is null)

BEGIN
insert into TABLE_LOG values('Trigger', systimestamp,
0, :new.LAST_MODIFIED_TIMESTAMP);
insert into TABLE_LOG values('Trigger', systimestamp,
1, ld.LAST_MODIFIED_TIMESTAMP);

IF not updating('LAST_MODIFIED_TIMESTAMP') THEN
insert into TABLE_LOG values('Trigger', systimestamp, 2, 'not
updating');
:new.last_modified_timestamp := SYSTIMESTAMP;
END IF;


END;


Test script:
-- 1st test
update FORWARD_FX_RATE_TS set last_modified_timestamp = '17-may-1974'
where CURRENCY_ID = 'CHF' and as_of_date = '29-Jun-2007';
-- 2nd test
--update FORWARD_FX_RATE_TS set as_of_date = '29-Jun-2007' where
CURRENCY_ID = 'CHF' and as_of_date = '29-Jun-2007';
commit;

-- Check value in the table
select * from FORWARD_FX_RATE_TS where CURRENCY_ID = 'CHF' and
as_of_date = '29-Jun-2007';

-- Check the logs
select * from table_log where LABEL = 'Trigger';
-- Cleaning
delete table_log where LABEL = 'Trigger';
commit;

drop trigger TU_FORWARD_FX_RATE_TS;


Reply With Quote
  #2  
Old   
DA Morgan
 
Posts: n/a

Default Re: Trigger deleting :new value - 11-06-2007 , 09:47 AM






Menthe&Basilic wrote:
Quote:
Hello

I have an update trigger that is for each row.
The goal is to detect if a timestamp field is updated, if not updated
it with system timestamp.
My problem is the value of this field is lost and I end up with null
value in the table.
I am attaching my testing script
I am using Oracle 10g.

Thanks for your help.
CREATE OR REPLACE TRIGGER TU_FORWARD_FX_RATE_TS
BEFORE UPDATE ON FORWARD_FX_RATE_TS referencing new as new, old as
old
FOR EACH ROW
--WHEN (new.last_modified_timestamp is null)

BEGIN
insert into TABLE_LOG values('Trigger', systimestamp,
0, :new.LAST_MODIFIED_TIMESTAMP);
insert into TABLE_LOG values('Trigger', systimestamp,
1, ld.LAST_MODIFIED_TIMESTAMP);

IF not updating('LAST_MODIFIED_TIMESTAMP') THEN
insert into TABLE_LOG values('Trigger', systimestamp, 2, 'not
updating');
:new.last_modified_timestamp := SYSTIMESTAMP;
END IF;


END;


Test script:
-- 1st test
update FORWARD_FX_RATE_TS set last_modified_timestamp = '17-may-1974'
where CURRENCY_ID = 'CHF' and as_of_date = '29-Jun-2007';
-- 2nd test
--update FORWARD_FX_RATE_TS set as_of_date = '29-Jun-2007' where
CURRENCY_ID = 'CHF' and as_of_date = '29-Jun-2007';
commit;

-- Check value in the table
select * from FORWARD_FX_RATE_TS where CURRENCY_ID = 'CHF' and
as_of_date = '29-Jun-2007';

-- Check the logs
select * from table_log where LABEL = 'Trigger';
-- Cleaning
delete table_log where LABEL = 'Trigger';
commit;

drop trigger TU_FORWARD_FX_RATE_TS;

Get rid of the WHEN clause and use NVL on :OLD.last_modified_timestamp.
http://www.psoug.org/reference/misc_func.html#mfnv
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu (replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.