PL SQL Interview
PL SQL Interview
PL SQL Interview
com/topic/oracle/insights/
Using PRAGMA - I
debasi
Join Date: Dec 2006
sdas Location: Bangalore ,India
Posts: 7,611
Moderat #1 Feb 25 '08
or
PRAGMA:-Signifies that the statement is a pragma (compiler directive).
Pragmas are processed at compile time, not at run time. They pass
information to the compiler.
A pragma is an instruction to the Oracle compiler that tells it to do
something. In this case you are telling Oracle to associate an error that
you choose to a variable that you choose. This pragma must go in the
declarative section of your block.
Types of PRAGMA
1.AUTONOMOUS_TRANSACTION
2.EXCEPTION_INIT
3.RESTRICT_REFERENCES
4.SERIALLY_REUSABLE
RESTRICTIONS:-
Pragma can't be used to mark all subprograms in a package as
autonomous.Only individual routines can be marked autonomous.It can
be coded any where in the declaration section of the sub program.
Once started, an autonomous transaction is fully independent.It shares
no locks,resources or commit dependencies with the main transaction.
ADVANTAGES:-
Unlike regular triggers autonomous triggers can contain COMMIT and
ROLLBACK.
LIMITATIONS:-
Changes made by a-t become visible to other transaction when the a-t
commits.The changes also become visible to the main transaction when
it resumes.
If a-t attempts to access a resource held by th main transaction(which
can't resume until the a-t routine exits),a deallock can occur.In that
case,Oracle raises an exception in the a-t,If the user tries to exit an a-t
without COMMIT OR ROLLBACK ,ORACLE RAISES AN EXCEPTION,in
both the cases the transaction is rolled back if the exception goes
unhandled.
Expand|Select|Wrap|Line Numbers
Expand|Select|Wrap|Line Numbers
9.
Using PRAGMA - II
debasi
Join Date: Dec 2006
sdas Location: Bangalore ,India
Posts: 7,611
Moderat #1 Jun 16 '07
or
This thread contains some useful tips/sample codes regarding some of advance concep
oracle, that the forum members may find useful.
PRAGMA EXCEPTION_INIT
====================
This is used to bind a user defined exception to a particular error number.
For example: To display USER DEFINED MESSAGE FOR ORACLE DEFINED NUMBER
---------------------
Expand|Select|Wrap|Line Numbers
1. DECLARE
2. I EXCEPTION;
3. PRAGMA EXCEPTION_INIT(I,-00001);
4. BEGIN
5. INSERT INTO DEPT VALUES(&DNO,'&DNAME','&LOC');
6. DBMS_OUTPUT.PUT_LINE('ONE RECORD INSERTED');
7. EXCEPTION
8. WHEN I THEN
9. DBMS_OUTPUT.PUT_LINE('DUPLICATE VALUE');
10. END;
11.
dup_val_on_index, -0001
timeout_on_resource, -0051
invalid_cursor, -1001
not_logged_on, -1012
login_denied, -1017
too_many_rows, -1422
zero_divide, -1476
invalid_number, -1722
storage_error, -6500
program_error, -6501
value_error, -6502
rowtype_mismatch, -6504
cursor_already_open, -6511
access_into_null, -6530
collection_is_null , -6531
subscript_outside_limit, -6532
subscript_beyond_count , -6533
debasi
Join Date: Dec 2006
sdas Location: Bangalore ,India
Posts: 7,611
Moderat #2 Jun 16 '07
or
re: Using PRAGMA - II
RESTRICT_REFERENCES Pragma
===========================
This pragma was used to assert to the PL/SQL compiler the purity level of a packaged
RESTRICT_REFERENCES pragma had to be included in the package specification if you
inside a SQL statement (directly or indirectly).
This pragma confirms to Oracle database that the function as the specified side-effects
such side-effects.
Usage is as follows:
WNDS: Writes No Database State. States that the function will not perform any DMLs.
WNPS: Writes No Package State. States that the function will not modify any Package
RNDS: Reads No Database State. Analogous to Write. This pragma affirms that the fun
database tables.
RNPS: Reads No Package State. Analogous to Write. This pragma affirms that the func
variables.
You can declare the pragma RESTRICT_REFERENCES only in a package spec or object
to four constraints (RNDS, RNPS, WNDS, WNPS) in any order. To call the function from
specify all four constraints. No constraint implies another. For example, WNPS does no
When you specify TRUST, the function body is not checked for violations of the constra
function is trusted not to violate them.
If you specify DEFAULT instead of a function name, the pragma applies to all functions
type spec (including, in the latter case, the system-defined constructor). You can still d
individual functions. Such pragmas override the default pragma.
syntax
========
Expand|Select|Wrap|Line Numbers
1. PRAGMA RESTRICT_REFERENCES (
2. function_name, WNDS [, WNPS] [, RNDS] [, RNPS] [, TRUST] );
3.
In the following example, the pragma applies to the second declaration of isok:
Expand|Select|Wrap|Line Numbers
DEFAULT
----------------
This specifies that the pragma applies to all functions in the package spec or object typ
the pragma for individual functions. Such pragmas override the default pragma.
debasisdas
Moderator
re: Using PRAGMA - II
SERIALLY_REUSABLE:
====================
This pragma lets the PL/SQL engine know that package-level data should not persist be
data.
Package data (global variables in package specification etc.) by default persists for an
package is recompiled). Globally accessible data structures can cause some side effect
cursor is left open in a package. In addition, a program can use up lots of real memory
it if the data is stored in a package-level structure.
The global memory for serially reusable packages is pooled in the System Global Area
individual users in the User Global Area (UGA). That way, the package work area can b
the server ends, the memory is returned to the pool. Each time the package is reused,
initialized to their default values or to NULL.
The advantage is that based on the pragma, a package state can be reduced to a singl
package as opposed to the package being available for the whole session.
20.