can you write commit in triggers?
Answers were Sorted based on User's Feedback
Answer / guru
----------- without AUTONOMOUS_TRANSACTION
CREATE or REPLACE TRIGGER parts_trig
BEFORE INSERT ON parts
FOR EACH ROW
BEGIN
INSERT INTO parts_log VALUES(:new.pnum, :new.pname);
END;
/
INSERT INTO parts VALUES (1040, 'Head Gasket');
COMMIT;
INSERT INTO parts VALUES (2075, 'Oil Pan');
ROLLBACK;
SELECT * FROM parts ORDER BY pnum;
SELECT * FROM parts_log ORDER BY pnum;
----------- using AUTONOMOUS_TRANSACTION
CREATE or REPLACE TRIGGER parts_trig
BEFORE INSERT ON parts FOR EACH ROW
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO parts_log VALUES(:new.pnum, :new.pname);
COMMIT; -- only for AUTONOMOUS_TRANSACTION
END;
/
INSERT INTO parts VALUES (1040, 'Head Gasket');
COMMIT;
INSERT INTO parts VALUES (2075, 'Oil Pan');
ROLLBACK;
/
Please Check This
Thanks
Is This Answer Correct ? | 6 Yes | 0 No |
Answer / selvam.p
No, In normal condition, commit or rollback inside the
trigger is not possible.
Is This Answer Correct ? | 5 Yes | 2 No |
Answer / sudhir
by default Trigger doesnt allow a commit;
however we can create a stored procedure which will only do
commit.
create or replace procedure to_commit_trigger
begin
commit();
end to_commit_trigger
now execute this stored procedure to_commit_trigger inside a
trigger to perform a commit. However it will cause serious
performance issues.
Is This Answer Correct ? | 0 Yes | 3 No |
How would you configure your networking files to connect to a database by the name of DSS which resides in domain icallinc.com?
In Oracle 9i what does "i" Stands for?
What are the various oracle database objects?
Point out the difference between user tables and data dictionary?
How will you write a query to get a 5th rank student from a table student_report?
Explain what does a control file contain?
I need to get the values of the previous quarter.how to do this?eg: if my cuurent month is may i need to get the datas of the month jan,feb,march.Can it be done in oracle.I tried with date function q but for the month jan its not retriving the previous quarter(oct-dec).how to solve this.plpz anyone help me?
why pl sql doesn't support retrieving multiple records
What is the difference between a vector and an Array? (Java)
How to create id with auto_increment on oracle?
How can you tell how much space is left on a given file system and how much space each of the file systems subdirectories take-up?
What is where clause in oracle?