You are on page 1of 5

8/17/2014 PRAGMA(Pragma Autonomous_transaction) - erpSchools

http://erpschools.com/uncategorized/pragmapragma-autonomous_transaction 1/5

Prasanth Boge
Apr 12, 2011
UNCATEGORIZED
PRAGMA(Pragma
Autonomous_transaction)
PRAGMASignifies that the statement is a pragma (compiler directive). Pragmas are
processed at compile time, not at run time. They do not affect the meaning of a
program; they simply convey information to the compiler.1) Autonomous Transaction
Autonomous Transactions is the child transaction, which are Independent of Parent
transactions. In Our Example, p1 is child transaction, which is used in the Parent
transaction.
Example: -
CREATE or REPLACE Procedure p1 IS
Pragma Autonomous_transaction;
BEGIN
INSERT INTO TEST_T VALUES (1111,PHANI1);
COMMIT;
END;
In the Declaration section, you will declare this Transaction as the Autonomous
Transaction.
DECLARE
A NUMBER;
BEGIN
INSERT INTO TEST_T VALUES (2222,JACK);
P1;
ROLLBACK;
END;
NOW Table has (1111,PHANI) Record. COMMIT in the PROCEDURE P1 have not
commit the Outside (p1) DML operations. It will just commit p1 transactions.
The ROLLBACK will not rollback PHANI record, it will just rollback the JACK record.
CREATE or REPLACE Procedure p1 IS
BEGIN
INSERT INTO TEST_T VALUES (1111,PHANI1);
COMMIT;
END;
If I remove the Pragma Autonomous_transaction From the declaration section, then
this transaction will become the normal transaction. Now if you try to use the same
parent transaction as given below.
Search
Apps Questions
Ask a Question
August 2014
M T W T F S S
Jul
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
POPULAR QUESTIONS

Ad by Mov ie Mode
erpSchools
7,017 people like erpSchools.
Facebook social plugin
Like
Specify the steps that need to be
done starting from creating an invoice
until transferring it to GL in AP.
asked by
Prudhvi Avuthu
What table holds the link between
ARTICLES

SCRIPTS

TRAININGS

CONTACT
Recommend
8/17/2014 PRAGMA(Pragma Autonomous_transaction) - erpSchools
http://erpschools.com/uncategorized/pragmapragma-autonomous_transaction 2/5
>> delete from TEST_T;
DECLARE
A NUMBER;
BEGIN
INSERT INTO TEST_T VALUES (2222,JACK);
P1; This transaction has ended with the COMMIT;
ROLLBACK;
END;
After executing the above transaction, you can see BOTH records got Inserted (PHANI
and JACK records). Here COMMIT in P1 will commit both transactions (PHANI and JACK
Records Insert) And then Rollback. Since, there are no transactions happening
between COMMIT and ROLLBACK. Our ROLLBACK is not doing any ROLLBACK.
Note: IF COMMIT is not given in P1 then, the ROLLBACK will do the ROLLBACK both
the INSERT transaction (PHANI Record which is in p1 procedure and JACK Record).
2) Pragma Restrict_references
It gives the Purity Level of the Function in the package.
CREATE OR REPLACE PACKAGE PKG12 AS FUNCTION F1 RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES (F1, WNDS,
RNDS,
WNPS,
RNPS);
END PKG12;
CREATE OR REPLACE PACKAGE BODY PKG12 AS
FUNCTION F1 RETURN NUMBER IS
X NUMBER;
BEGIN
SELECT EMPNO INTO X FROM SCOTT.EMP
WHERE ENAME LIKE SCOTT;
DBMS_OUTPUT.PUT_LINE (X);
RETURN (X);
END F1;
END PKG12;
You will get the Violate Its Associated Pragma Error. This in Purity Level, we said
It cannot read from the database. RNDS (In Our Function F1, we have SELECT
STATEMENT which is reading the data from the database).
3) Pragma SERIALLY_REUSABLE
In my 5 Years of Experience in the Oracle Applications, I have never found the
requirement to use this feature :). But, I found this feature is used in some standard
Oracle Packages. We may use this feature for improving the performance or to meet
certain requirements.
This pragma is appropriate for packages that declare large temporary work areas that
are used once and not needed during subsequent database calls in the same session.
You can mark a bodiless package as serially reusable. If a package has a spec and
body, you must mark both. You cannot mark only the body.
The global memory for serially reusable packages is pooled in the System Global Area
OM and AR?
asked by
Prudhvi Avuthu
Can we create an Invoice without
a PO in payables?
asked by
Prudhvi Avuthu
What does TCA stand for? What
is it used for ?
asked by
Prudhvi Avuthu
Name the standard Key Flexfields
in AR.
asked by
Prudhvi Avuthu
What is the name of the program
used to import expense reports into
AP? Name the tables that store the
expense reports related date.
asked by haritha
What are Aging Periods used for
in AP?
asked by
Prudhvi Avuthu
Can you make a partial payment
for an invoice in AP?
asked by haritha
What are Payment Terms?
asked by
Prudhvi Avuthu
What is the process/steps for
Vendor Conversion?
asked by
Prudhvi Avuthu
8/17/2014 PRAGMA(Pragma Autonomous_transaction) - erpSchools
http://erpschools.com/uncategorized/pragmapragma-autonomous_transaction 3/5
(SGA), not allocated to individual users in the User Global Area (UGA). That way, the
package work area can be reused. When the call to the server ends, the memory is
returned to the pool. Each time the package is reused, its public variables are
initialized to their default values or to NULL.
Serially reusable packages cannot be accessed from database triggers or other PL/SQL
subprograms that are called from SQL statements. If you try, Oracle generates an
error.
Examples
WITH PRAGMA SERIALLY_REUSABLE
The following example creates a serially reusable package:
CREATE PACKAGE pkg1 IS
PRAGMA SERIALLY_REUSABLE;
num NUMBER := 0;
PROCEDURE init_pkg_state(n NUMBER);
PROCEDURE print_pkg_state;
END pkg1;
/
CREATE PACKAGE BODY pkg1 IS
PRAGMA SERIALLY_REUSABLE;
PROCEDURE init_pkg_state (n NUMBER) IS
BEGIN
pkg1.num := n;
END;
PROCEDURE print_pkg_state IS
BEGIN
dbms_output.put_line(Num: || pkg1.num);
END;
END pkg1;
/
begin
pkg1.init_pkg_state(10);
pkg1.PRINT_PKG_STATE;
end;
Num: 10
begin
pkg1.PRINT_PKG_STATE;
end;
Num: 0
Note: The first block is changing the value of the variable (num) to 10 and if I check
the value in same block then it is showing the changed value that is 10. But, if I try
to check the value of the (num) variable then it should the default value given to it
(i.e.) 0
WITHOUT PRAGMA SERIALLY_REUSABLE
8/17/2014 PRAGMA(Pragma Autonomous_transaction) - erpSchools
http://erpschools.com/uncategorized/pragmapragma-autonomous_transaction 4/5
CREATE OR REPLACE PACKAGE pkg1 IS
num NUMBER := 0;
PROCEDURE init_pkg_state(n NUMBER);
PROCEDURE print_pkg_state;
END pkg1;
CREATE PACKAGE BODY pkg1 IS
PROCEDURE init_pkg_state (n NUMBER) IS
BEGIN
pkg1.num := n;
END;
PROCEDURE print_pkg_state IS
BEGIN
dbms_output.put_line(Num: || pkg1.num);
END;
END pkg1;
begin
pkg1.init_pkg_state(10);
pkg1.PRINT_PKG_STATE;
end;
>>Num: 10
begin
pkg1.PRINT_PKG_STATE;
end;
>>Num: 10
Note: Now, you may noticed the difference. The second block is giving us the
changed value.
DROP PACKAGE pkg1;
RELATED POSTS
UNCATEGORIZED /
Respond to workflow notification from a DB procedure
UNCATEGORIZED /
How to dowload Worklflow file(.wft) from Front end:
UNCATEGORIZED /
WorkFlow Commands for Dowlaond and Upload:
UNCATEGORIZED /
Workflow tables and its usage
UNCATEGORIZED /
Script to find Oracle APIs for any module?
UNCATEGORIZED /
FOR KILLING A CONCURRENT REQUEST AND FOR KILLING A SESSION
UNCATEGORIZED /
How to submit XMLP Report using a PL/SQL Script:
UNCATEGORIZED /
8/17/2014 PRAGMA(Pragma Autonomous_transaction) - erpSchools
http://erpschools.com/uncategorized/pragmapragma-autonomous_transaction 5/5
XMLP tables in oracle apps
UNCATEGORIZED /
XML/BI Publisher Template/Report Migration UNIX Scripts
UNCATEGORIZED /
How to Display Leading Zeros in XMLP Report Excel Output

BACK TO TOP
TAGS
Add ADF AP API ar BI concurrent program Controller conversion email forms iexpense iexpenses interface internal requisition internal
sales order inventory Invoices JAva o2c OAF OAF Page om Oracle Oracle Apps order to cash output payables payment batch
personalization position heirarchy Prepayments process Publisher R12 REceivables Remove responsibilities responsibility script users UTL_MAIL
workflow xml XML Publisher
Copyright erpSchools & Prudhvi Avuthu
Copying of content without written permission is not allowed.
User Guides for ORACLE
APPLICAITONS
To know the Application version
before upgrade and current version
LEAVE A REPLY
YOUR NAME
YOUR EMAIL
YOUR WEBSITE
POST COMMENT

You might also like