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 |
According to oracle specification VIEW is a object. OBJECT that means anything stored in the oracle database that has the physical existence.why VIEW doesn't take memory in oracle database, but it is treated as a object ?Please explain ?
What is a named program unit?
What is a synonym? What are its various types?
How to update values on multiple rows in oracle?
Explain the use of Merge statement in oracle 11g
Whether Oracle satisfy more codd rules or db2 satisfy more codd rules? How meny of each can satisfy ? Please answer me. Advance thanks
How to start a specific oracle instance?
What are group functions in oracle?
which clause we are not used in where clause?
How to define and use table alias names in oracle?
How to drop a stored function?
Is there a combination of "like" and "in" in sql?