GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 86 of 241    Print  
what is pragma?
can any one give me the example of autonomous Transaction ?
can we change the order of procedure parameter while calling procedure?

  
Total Answers and Comments: 6 Last Update: February 18, 2008     Asked by: manali 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: pankaj_gauba
 

prgma is a compiler directive, it takes the oracle description error name from database for oracle error code.

Example of autonous transaction:

Autonomous Transaction is a feature of oracle 8i which  maintains  the state of its transactions and save  it ,  to affect with the commit or rollback  of the surrounding transactions.

 

Here is the simple example to understand this :-

 

ora816 SamSQL :> declare

  2   Procedure InsertInTest_Table_B

  3    is

  4    BEGIN

  5     INSERT into Test_Table_B(x) values (1);

  6     Commit;

  7    END ;

  8    BEGIN

  9      INSERT INTO Test_Table_A(x) values (123);

 10      InsertInTest_Table_B;

 11      Rollback;

 12    END;

 13  /

 

PL/SQL procedure successfully completed.

 

ora816 SamSQL :> Select * from Test_Table_A;

         X

----------

       123

ora816 SamSQL :> Select * from Test_Table_B;

         X

----------

         1

 

 Notice in above pl/sql  COMMIT at line no 6 , commits the transaction at  line-no 5 and  line-no 9. The Rollback at line-no 11 actually did nothing.  Commit/ROLLBACK at nested transactions will commit/rollback all  other DML transaction before that. PRAGMA AUTONOMOUS_TRANSACTION override this behavior.

 

Let us the see the following example with PRAGMA AUTONOMOUS_TRANSACTION.

 

ora816 SamSQL :> declare

  2     Procedure InsertInTest_Table_B

  3     is

  4     PRAGMA AUTONOMOUS_TRANSACTION;

  5       BEGIN

  6         INSERT into Test_Table_B(x) values (1); 

  7         Commit;

  8       END ;

  9       BEGIN

 10        INSERT INTO Test_Table_A(x) values (123);

 11        InsertInTest_Table_B;

 12        Rollback;

 13       END;

 14     /

 

PL/SQL procedure successfully completed.

 

ora816 SamSQL :> Select * from Test_Table_A;

 

no rows selected

 

ora816 SamSQL :> Select * from Test_Table_B;

 

         X

----------

         1

 

With PRAGMA AUTONOMOUS_TRANSACTION , the transaction state maintained independently . Commit/Rollback of nested transaction will no effect the other transaction. It is advisable to increase the value of  TRANSACTIONS parameter in the INIT parameter file to allow for the extra concurrent transaction .

 

can we change the order of procedure parameter while calling procedure?
 Yes we can change the order , it is called Named Notation

 



Above answer was rated as good by the following members:
harit79
June 11, 2006 16:24:05   #1  
sagar singh        

RE: what is pragma? can any one give me the exam...
Pragmas are pre-compiler directives.
 
Is this answer useful? Yes | No
June 12, 2006 22:02:53   #2  
KHARTHY        

RE: what is pragma? can any one give me the exam...
ABOUT PRAGMApragma'S are private transactions which does not affect anyother transaction. consider procedure1 is calling procedure2 after finishing a transaction in the second procedure if a error occurs in the procedure1 then all the transactions will be rolled back ( even tat happend in the procedure2) if pragma_autonomous transaction is used in the second procedure ...tat transaction can be savedhttp://www.psoug.org/reference/autonomous_tx.htmlI HOPE TAT LINK WILL GIVE U A MUCH BETTER PICTUREREGARDSd.r. KHARTHY
 
Is this answer useful? Yes | No
June 18, 2006 03:44:26   #3  
Shivraj G. Gutte        

RE: what is pragma? can any one give me the exam...

Pragama is compile directive .

Example of Autonomous transactions

Suppose you are updating value from table and you don't have update trigger on that table

but still you want to maintain a log entry for this update in seprate table.

You can write a procedure and call that procedure to do this . But you can not use COMMIT in this called procedure because it will save the entire transaction.

To avoid this you can delclare this procedure as autonomous transaction procedure so that the execution of this procedure will be treated as totally diff. transaction and you can issue commit in called procedure without affecting the main transaction.


 
Is this answer useful? Yes | No
June 22, 2006 07:34:25   #4  
pankaj_gauba Member Since: November 2005   Contribution: 16    

RE: what is pragma? can any one give me the exam...

prgma is a compiler directive it takes the oracle description error name from database for oracle error code.

Example of autonous transaction:

Autonomous Transaction is a feature of oracle 8i which maintains the state of its transactions and save it to affect with the commit or rollback of the surrounding transactions.

Here is the simple example to understand this :-

ora816 SamSQL :> declare

2 Procedure InsertInTest_Table_B

3 is

4 BEGIN

5 INSERT into Test_Table_B(x) values (1);

6 Commit;

7 END ;

8 BEGIN

9 INSERT INTO Test_Table_A(x) values (123);

10 InsertInTest_Table_B;

11 Rollback;

12 END;

13 /

PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A;

X

----------

123

ora816 SamSQL :> Select * from Test_Table_B;

X

----------

1

Notice in above pl/sql COMMIT at line no 6 commits the transaction at line-no 5 and line-no 9. The Rollback at line-no 11 actually did nothing. Commit/ROLLBACK at nested transactions will commit/rollback all other DML transaction before that. PRAGMA AUTONOMOUS_TRANSACTION override this behavior.

Let us the see the following example with PRAGMA AUTONOMOUS_TRANSACTION.

ora816 SamSQL :> declare

2 Procedure InsertInTest_Table_B

3 is

4 PRAGMA AUTONOMOUS_TRANSACTION;

5 BEGIN

6 INSERT into Test_Table_B(x) values (1);

7 Commit;

8 END ;

9 BEGIN

10 INSERT INTO Test_Table_A(x) values (123);

11 InsertInTest_Table_B;

12 Rollback;

13 END;

14 /

PL/SQL procedure successfully completed.

ora816 SamSQL :> Select * from Test_Table_A;

no rows selected

ora816 SamSQL :> Select * from Test_Table_B;

X

----------

1

With PRAGMA AUTONOMOUS_TRANSACTION the transaction state maintained independently . Commit/Rollback of nested transaction will no effect the other transaction. It is advisable to increase the value of TRANSACTIONS parameter in the INIT parameter file to allow for the extra concurrent transaction .

can we change the order of procedure parameter while calling procedure?
Yes we can change the order it is called Named Notation


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 01, 2008 21:32:41   #5  
g_sidhu Member Since: August 2007   Contribution: 122    

RE: what is pragma? can any one give me the example of autonomous Transaction ?can we change the order of procedure parameter while calling procedure?

Using Named & Combination Parameter passing Methods you can change the order of parameter in a procedure
Named: List actual parameters in arbitrary order by associating each with its corresponding formal parameter.

Combination: List some of the actual parameters as positional and some as named.


 
Is this answer useful? Yes | No
February 18, 2008 15:29:56   #6  
g_sidhu Member Since: August 2007   Contribution: 122    

RE: what is pragma? can any one give me the example of autonomous Transaction ?can we change the order of procedure parameter while calling procedure?
A pragma is compiler directive. Pragmas are processed at compile time not at run time. They pass information to the compiler.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape