Вы находитесь на странице: 1из 2

PL/SQL

CHAPTER 1 INTRO PLSQL blocks are of two types. Named and anonymous. Named are used for creating subroutines that are stored in databases and referenced later by their names. Pcode List of instructions to plsql engine after compilation. CHAPTER 1.2 SQL PLUS Substitution variables (&) Used to receive input for the plsql block. They cannot be used to output values as they no memory is allocated for them. SET VERIFY OFF used to see simple output when substitution variables are used. SET DEFINE character Change the substitution variable. DBMS_OUTPUT.PUT_LINE writes information to the buffer for storage. Chapter 2.1 No forward referencing allowed. Anchored Datatype (%TYPE) The Data type of variable is based on the database object. Labels <<label_name>> - Used particularly with nested blocks. END label_name. Chapter 4.2 ELSIF Elsif these statements are mutually exclusive. Chapter 5.1 Case statements Two forms, CASE and searched CASE statements. WHEN condition leads to a BOOLEAN result (true or false) Chapter 5.2 CASE Expressions Evaluates to a single value that may be assigned to a variable. Syntax slightly different to CASE statements. They can be used as elaborate columns of a SELECT statement. Data types in the condition of a Case Statement or expression should match. Statements should return the same data type. Chapter 6 LOOP, WHILE LOOP, FOR, CONTINUE Dont use EXIT, EXIT WHEN condition in while loop. FOR LOOP Loop counter should not be referenced outside the loop. Loop counter cannot be incremented or decremented inside the loop. NESTED LOOPS Use loop label <<loop_name>> when using nested loops. END LOOP loop_name. Chapter 8.1 Exceptions Allows a program to execute to completion in spite of errors. Helps isolate error handling routines. Enables event driven processing of errors. Types Built in exceptions and User defined exception. Chapter 8.2 Built In exceptions NO_DATA_FOUND, TOO_MANY_ROWS, ZERO_DIVIDE, LOGIN_DENIED, PROGRAM_ERROR, VALUE_ERROR and DUP_VALUE_ON_INDEX. They are implicitly raised. Only need to specify what action needs to be taken in case of an exception. When using COUNT(*), the NO_DATA_FOUND exception will not fire.

Chapter 9.1 Exception Scope Exception scope is the portion of the block covered by this exception. Exception Propagation - An exception defined in a block is global to any blocks enclosed by that block. Any exception defined in the outer block becomes global to the inner blocks. Chapter 9.2 User defined exceptions You need to declare these exceptions. Explicitly raised. Need to specify under what circumstances the exception was raised. IF statements are used to check whether to raise the exception or not. RAISE keyword is used in the IF statement to raise an user defined exception. Chapter 9.3 Exception Propagation When a runtime error is occurring in the declaration section or the exception handling section in the outer most block then this error cannot be caught. Only one exception can be raised per block. So two exceptions cannot be raised in a single block. The exception will propagate to the outer block. RERAISING AN EXCEPTION When we want to handle an exception in the inner block and then pass it to the outer block (by raising same exception from inside the exception). o Raise statement, when used in the exception handling section of the inner block, it is not followed by the exception name. Chapter 11.1 Cursor Manipulation Cursor is named, so it can be referenced. Two types. Implicit cursors and explicit cursors. During implicit cursors, oracle automatically performs open, fetch close operations. SQL%ROWCOUNT Implicit cursor attributes. Used to find out no of rows affected. Explicit Cursor Declare, open, fetch and close. RECORDS Composite data structures. o Three types. Table based, Cursor based and user defined. o %ROWTYPE Used when declaring records. Cursors are always fetched into a record. CURSOR ATTRIBUTES used to find the result of the cursor operation when fetched or opened. o %NOTFOUND, %FOUND, %ROWCOUNT, %ISOPEN Chapter 11.2 CURSOR FOR LOOPS o No need to open and close a cursor. Chapter 13.1 Triggers o Named plsql blocks stored in the database which are executed implicitly when a triggering event occurs. Triggering event can be DML, DDL, System even like startup or shut down and user event like log out. o :NEW Allows us to access the row currently being processed. It is of type TIGGERING_TABLE%TYPE. To access individual members of pseudorecord, .dot notation is used. For example :NEW.created_by := USER ;

Вам также может понравиться