Skip to main content

Posts

Showing posts from April, 2011

How PL/SQL Exceptions Are Raised ?

How PL/SQL Exceptions Are Raised Internal exceptions are raised implicitly by the run-time system, as are user-defined exceptions that you have associated with an Oracle error number using EXCEPTION_INIT . However, other user-defined exceptions must be raised explicitly by RAISE statements. Raising Exceptions with the RAISE Statement PL/SQL blocks and subprograms should raise an exception only when an error makes it undesirable or impossible to finish processing. You can place RAISE statements for a given exception anywhere within the scope of that exception. In Example 10-6 , you alert your PL/SQL block to a user-defined exception named out_of_stock . Example 10-6 Using RAISE to Force a User-Defined Exception DECLARE    out_of_stock   EXCEPTION;    number_on_hand NUMBER := 0; BEGIN    IF number_on_hand < 1 THEN       RAISE out_of_stock; -- raise an exception that we defined    END IF; EXCEPTION    WHEN out_of_stock THEN       -- handle the error       DBMS

What are the different types of pragma and where can we use them?

======================================================================== What are the different types of pragma and where can we use them? Pragma is a keyword in Oracle PL/SQL that is used to provide an instruction to the compiler. The syntax for pragmas are as follows PRAMA The instruction is a statement that provides some instructions to the compiler. Pragmas are defined in the declarative section in PL/SQL. The following pragmas are available: AUTONOMOUS_TRANSACTION: Prior to Oracle 8.1, each Oracle session in PL/SQL could have at most one active transaction at a given time. In other words, changes were all or nothing. Oracle8i PL/SQL addresses that short comings with the AUTONOMOUS_TRANSACTION pragma. This pragma can perform an autonomous transaction within a PL/SQL block between a BEGIN and END statement without affecting the entire transaction. For instance, if rollback or commit needs to take place within the block without effective the transaction outside the block, thi