469,306 Members | 1,896 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

How to access new value Statement Level Trigger

Hi All,
I want to access new value after upadate in statement level trigger.
But in my query I am getting old values.
Here is the Trigger Code:

CREATE OR REPLACE TRIGGER TEST_TRIGGER
AFTER UPDATE OF col3 on table_gyan
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
v_count NUMBER:=0;
v_temp_count NUMBER:=0;
BEGIN
SELECT Count(1) into v_count from table_gyan where col3='Y';
If v_count>0 THEN
SELECT COUNT(1) INTO v_temp_count from TRIGGER_TABLE;
if v_temp_count>0 THEN
UPDATE TRIGGER_TABLE SET ACTION='START';
COMMIT;
else
insert into TRIGGER_TABLE(ACTION) values('START');
commit;
end if;
END IF;
END;

.


Now when ever I am executing this query
update table_gyan set col3='Y'
where col1='3'
and col2='100'
Its not doing anything with TRIGGER_TABLE.


Please help me how to do it.

Regards,
Gyanendar
Oct 29 '08 #1
10 10928
Pilgrim333
127 100+
Are you sure any records are updated?

Pilgrim.
Oct 30 '08 #2
Are you sure any records are updated?

Pilgrim.
In the table records are getting updated but trigger is still taking Old value.
Nov 3 '08 #3
Pilgrim333
127 100+
Ok,

So now you have values in the table where col3 has the value 'Y' Try to update col3 now, and see if the trigger_table is updated.

Pilgrim.
Nov 3 '08 #4
Ok,

So now you have values in the table where col3 has the value 'Y' Try to update col3 now, and see if the trigger_table is updated.

Pilgrim.

No ,its not updating trigger_table values.
If before updation table contains 'Y' than its working .
Nov 3 '08 #5
amitpatel66
2,367 Expert 2GB
try using this code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE OR REPLACE TRIGGER TEST_TRIGGER
  3. AFTER UPDATE OF col3 on table_gyan
  4. DECLARE
  5. PRAGMA AUTONOMOUS_TRANSACTION;
  6. v_count NUMBER:=0;
  7. v_temp_count NUMBER:=0;
  8. BEGIN
  9. SELECT Count(1) into v_count from table_gyan where col3=:new.col3;
  10. If v_count>0 THEN
  11. SELECT COUNT(1) INTO v_temp_count from TRIGGER_TABLE;
  12. if v_temp_count>0 THEN
  13. UPDATE TRIGGER_TABLE SET ACTION='START';
  14. COMMIT;
  15. else
  16. insert into TRIGGER_TABLE(ACTION) values('START');
  17. commit;
  18. end if;
  19. END IF;
  20. END;
  21.  
Nov 4 '08 #6
Pilgrim333
127 100+
As this is a statement level trigger and firest once every statement, the individual values are not available in the trigger.

But the post of amitpatel66 makes us think, make it a row level trigger and use the code amitpatel66 posted and see if the trigger_table table gets updated.

Pilgrim.
Nov 4 '08 #7
amitpatel66
2,367 Expert 2GB
Yes this is for row level trigger.

@OP, are you looking at Row level trigger updates or statment level? Please confirm?
Nov 4 '08 #8
Yes this is for row level trigger.

@OP, are you looking at Row level trigger updates or statment level? Please confirm?
Yes,
Finally I made it row level trigger and every thing worked fine.

But,if 100 rows of table get updated than ,tigger will get fired for all the 100 rows and does the same work.To avoid this problem ,I was thinking for statement level trigger.

Guy's can we have statement level trigger for this work.

Regards,
Gyanendar
Nov 7 '08 #9
Pilgrim333
127 100+
So, the same code works for row level statement, but doesn't work for the statement level trigger?

Pilgrim.
Nov 7 '08 #10
amitpatel66
2,367 Expert 2GB
Yes,
Finally I made it row level trigger and every thing worked fine.

But,if 100 rows of table get updated than ,tigger will get fired for all the 100 rows and does the same work.To avoid this problem ,I was thinking for statement level trigger.

Guy's can we have statement level trigger for this work.

Regards,
Gyanendar
No you cannot. If you want it to work for all the records then you should have row level trigger
Nov 7 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Allan Hart | last post: by
14 posts views Thread by Sean C. | last post: by
6 posts views Thread by Peter Frost | last post: by
49 posts views Thread by Yannick Turgeon | last post: by
7 posts views Thread by peter.morin | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.