Skip to main content

Posts

Showing posts with the label Commit

Question 13: DDL and Commit

I have updated some tables and before commit if I will give one DDL command means what will happen? For example CREATE TABLE test(fldname number(10)); insert into test (fldname) values (10); insert into test (fldname) values (20); After that without giving Commit statement, I issued one DDL command CREATE TABLE test1( sno number(10)) What aobut the previous inserts? Is it committed or not? explain. Answer: I checked this and found the following 3 points. Point No. 1: If we give a DDL command with syntax error means it will not commit and gives the error. For example the following statement CREATE TABLE test(fldname number(10), ); note that the comma, gives "invalid identifier.. " error and without committing the INSERT statements. Point No. 2: If the given DDL command executes without any error means it will auto commit the INSERT statements. Point No. 3: If we give a DDL command without any syntax error and that statement not execute also auto commit the INSERT st...

Question 12: What is PRAGMA AUTONOMOUS_TRANSACTION?

You are running a pl/sql block or procedure called parent In that procedure you called another one procedure namely child and that procedure contains commit statement. After calling the child procedure the transactions done in parent procedure are also committed due to the child procedure commit statement. But you want to rollback or commit the parent procedure whole transactions based on your requirement after the calling procedure child. In this situation, you should add the "pragma autonomus transaction" in child procedure. If you add this statement then it acts as a separate. If you use commit in child procedure it will not affect the parent procedure. Example : CREATE OR REPLACE PROCEDURE parent() AS BEGIN UPDATE tab1 SET fieldname = value WHERE condition; UPDATE tab2 SET fieldname = value WHERE condition; child(); UPDATE tab4 SET fieldname = value WHERE condition; IF parentcondition COMMIT; ELSE ROLLBACK; END IF; END. CREATE OR REPLACE PROCEDURE child() AS PRAGMA AUTONO...