Skip to main content

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 AUTONOMOUS_TRANSACTION;
BEGIN
UPDATE tab3 SET fieldname = value WHERE condition;
COMMIT;
END.


In above case tab1, tab2 and tab4 tables transactions will commit or rollback based on the parentcondition. but tab3 updation will always commits, that is not consider the parent procedure.

lot of interview quesitions and answers, objective type questions with answers also available. To see click http://atchaya.com/ora/orahome.html

Comments

Popular posts from this blog

Question 9: null in where clause

The EMP table contains these columns: LAST NAME VARCHAR2(25) SALARY NUMBER(6,2) DEPARTMENT_ID NUMBER(6) You need to display the employees who have not been assigned to any department. You write the SELECT statement: SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL; What is true about this SQL statement? A. The SQL statement displays the desired results. B. The column in the WHERE clause should be changed to display the desired results. C. The operator in the WHERE clause should be changed to display the desired results. D. The WHERE clause should be changed to use an outer join to display the desired results. Answer: C Explanation: The operator in the WHERE clause should be changed to display the desired results. There are times when you want to substitute a value in place of NULL. Oracle provides this functionality with a special function, called NVL(). You can use operation equal with the keywords IS NULL, or you can achieve desired results using NVL() fu...

21.Oracle - The self documenting dictionary

Oracle - The self documenting dictionary Oracle's Data dictionary is itself self documenting. we can query DICTIONARY AND DICT_COLUMNS views for descriptions of the data dictionary views and their columns. The following query gives the descriptions of all of the data dictionary views. SELECT table_name, comments FROM dictionary ORDER BY table_name; It gives the large amount of output. By using where class we can focus a smaller set of views as like the following query. SELECT table_name, comments FROM dictionary WHERE table_name LIKE '%TABLE%' ORDER BY table_name It returns all views containing the word 'TABLE' Like wise We can query the DICT_COLUMNS view also. It gives the descriptions for the columns for all views. Following query retrieves descriptions for the columns in ALL_TAB_COLUMNS. SELECT column_name, comments FROM dict_columns WHERE table_name = 'ALL_TAB_COLUMNS'; This is a sample one. We can learn lot about oracle through data d...

Question 15

Write a PL/SQL Program for the following output --*-- -***- ***** -***- --*-- Answer The output based on the value of 'n' declare n number(2) default 20; i number(2); j number(2); h number(2); s number(2); b varchar2(1) default 'I'; begin s := 1; if n mod 2 = 0 then n := n+1; end if; h := n/2 -1; for i in 1..n loop for j in 1..h loop dbms_output.put('-'); end loop; for j in 1..s loop dbms_output.put('*'); end loop; for j in 1..h loop dbms_output.put('-'); end loop; dbms_output.put_line(' '); if n = s then b := 'D'; end if; IF b='I' then s := s+2; h := h-1; else s := s-2; h := h+1; end if; end loop; end;