473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 11473
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

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

Similar topics

2
by: Allan Hart | last post by:
Hi.. I'd very much appreciate it if someone would tell me how to translate a statement level trigger written in Oracle to its equivalent (if there is one) in MS SQL Server. Ditto for a row...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
7
by: peter.morin | last post by:
Issue: I am inserting an Oracle record containing insert trigger via Access 2002 using the code below. The issue is that the sequence from the acSaveRecord is not reflected after the insert so...
6
by: Hardy Wang | last post by:
Hi all, I have the following codes, but SCOPE_IDENTITY() just returns NULL to me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works fine!! Since I have a trigger on the...
4
by: rama | last post by:
Hi, I am a bit troubled with the row-level triggers which PostgreSQL uses when using update table cpmmand. For instance, if the primary key column has values 1,2,3,... and i want to update the...
17
by: Rico | last post by:
Hello, I am in the midst of converting an Access back end to SQL Server Express. The front end program (converted to Access 2003) uses DAO throughout. In Access, when I use recordset.AddNew I...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.