0% found this document useful (0 votes)
74 views

Pragma Oracle PLSQL

Pragmas provide instructions to the compiler to pass necessary information, the most common being EXCEPTION_INIT which associates a user-defined exception with an Oracle error code, AUTONOMOUS_TRANSACTION which allows child blocks to commit independently of the parent block, and SERIALLY_REUSABLE which allows the compiler to deduce the package state from just a server call rather than the session level. The document also discusses data types like %TYPE and %ROWTYPE for declaring fields and records that match table columns, and functions like STRING2DATE that use EXCEPTION_INIT to handle errors converting a string to a date.

Uploaded by

Azam Sajid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Pragma Oracle PLSQL

Pragmas provide instructions to the compiler to pass necessary information, the most common being EXCEPTION_INIT which associates a user-defined exception with an Oracle error code, AUTONOMOUS_TRANSACTION which allows child blocks to commit independently of the parent block, and SERIALLY_REUSABLE which allows the compiler to deduce the package state from just a server call rather than the session level. The document also discusses data types like %TYPE and %ROWTYPE for declaring fields and records that match table columns, and functions like STRING2DATE that use EXCEPTION_INIT to handle errors converting a string to a date.

Uploaded by

Azam Sajid
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Pragma use to provide an PRAGMA EXCEPTION_INIT.

%type :-declare a field %rowtype :-declare a record


v_EmpName emp.ename%TYPE; v _emp emp%ROWTYPE;
allows us to associate an ORA error code to an user-
instruction to the compiler. ANY is equivalent to IN operator. ALL is equivalent to NOT IN
defined PL/SQL exception.
processed at compile time (rather condition.
than runtime) to pass necessary create or replace function string2date (str in varchar2)
information to the compiler;most return date is
popular prama types:1.exception- retDate date;
not_valid_date exception;
init 2. pragma-autonomus transaction PRAGMA EXCEPTION_INIT(not_valid_date,-1841);
2. begin
CREATE OR REPLACE retDate := to_date(str,'yyyy-mm-dd');
CREATE TABLE t ( PROCEDURE child_block IS
test_value VARCHAR2(25));
return retDate;
PRAGMA exception
CREATE OR REPLACE AUTONOMOUS_TRANSACTION; when not_valid_date then
PROCEDURE child_block IS
BEGIN
dbms_output.put_line('Error: the string '||str||'
BEGIN INSERT INTO t cannot be converted to a date!');
INSERT INTO t (test_value) return null;
(test_value) VALUES
VALUES ('Child block insert');
end;
('Child block insert'); /
COMMIT; COMMIT;
END child_block; END child_block;
/ /
select string2date('werrwer') from dual;
CREATE OR REPLACE -- empty the test table
PROCEDURE parent_block IS TRUNCATE TABLE t;
STRING2DA
BEGIN -- run the parent procedure ---------
INSERT INTO t exec parent_block;
(test_value)
VALUES -- check the results
('Parent block insert'); SELECT * FROM t; Error: the string werrwer cannot be converted to a
Result:- date!
child_block; Child block insert
We’re defining a new exception not_valid_date, but it
Proc a
ROLLBACK;
( will be never called if we don’t associate it to the ORA-
END parent_block;
Proc b(); 1841 error using the PRAGMA.
/
Rollback; Once we have made the association Oracle knows that,
)
-- run the parent procedure
Proc b( in case of the ORA-1841 error, the not_valid_date
exec parent_block
PRAGMA exception must be raised.
AUTONOMOUS_TRANSACTION AUTONOMOUS_TRANSACTION – Compiler allows
-- check the results
-------some logic
SELECT * FROM t;
Commit; schema objects like subprograms, PL/SQL blocks, or
Result:-
Parent block insert
); triggers to commit their transaction within their scope.
Proc b only commit,rem proc a
Child block insert
rollback
2.on update will show the RESTRICT_REFERENCES – Allows the compiler to scan
updated data either commit run the database purity during package compilation. It can
or not.(show uncommitted be used in packages only.
data) exp :update sal
SERIALLY_REUSABLE – Compiler deduces the package
EXCEPTION_INIT – Compiler associates a user defined
state from session level to just a server call. It can be
exception name with an exception number.
used in Package spec only.

PRAGMA INLINE – New member of oracle pragma


family. It is used to explicitly inline a program unit.

You might also like