You are on page 1of 3

PL/SQL ====== Procedural language SQL is a method to provide programming features to SQL.

It is called a method since, it can not be activated independentlly. Most of the Oracle products like sql * plus, forms,reports,graphics,oracle financial, oracle manufacturing etc. support plsql programming methods . Since, plsql is developed by Oracle Corpn., it may not be supported by other RDBMS products like MS/SQL, SYBASE, INFORMIX etc. PL/SQL supports the following features as any of Programming Language : - Use of Variables - Control Statements ____ Conditional statements. _______ Looping statements. - Statements/Commands for specific tasks. VARIABLES: -----------------These are temporary locations in memory where values are stored. These will be identified by names given by the program. Main purpose of variable is to pass value from one process to another process. - How to Declare a variable in PLSQL. ? Syntax: -----<variable name> data type [(,size>)] [:= <initial value>]; - How to assign Value into variable ? Syntax: -----<variable name> := <value> ; := = Assignment Operator. CONDITIONAL STATEMENTS : ---------------------Used to control the flow of program execution. Since, program execution starts from top to bottom, conditional statements are used to take decision to process or to skip a particular set of statements/commands. Conditional statements are also called as branching statements since they transfer control from one part of the program to another part. But this branching or jumping can not be backwards. PLSQL provides the following conditional statements: 1) IF <condition> THEN statement-1; [,...]

[ ELSIF <condition> THEN ] statement-2; [,...] [ ELSE ] statement-3; [,...] END IF; 2) <statement> WHEN <condition>; LOOPING STATEMENTS : -----------------These are used to repeat statement or set of statements many times based on counter (fixed number of times) or condition (till the condition is true). Plsql provides two types of loops 1) For Loop 2) While Loop FOR LOOP : -------FOR <variable> IN [REVERSE] <st.value> .. <end value> LOOP statement-1; statement-2; END LOOP; The statements between LOOP and END LOOP will be executed from start value till the end value. FOR statement itself will declare and intialise with start value & for each occurence of loop value of variable is incremented by one. Once the variale value becomes more than end value, then loop terminates. If REVERSE is used loop variable initial value will be end value and for each occurance of loop value of the variable is decremented by one. Once, the value becomes less than start value then loop terminates. Variable data type is always number only. WHILE LOOP : ---------WHILE <condition> LOOP <statements> END LOOP; Loop starts and continues till the condition is false. For each occurence of loop, condition is evaluated. If condition is true then control comes inside the loop and execute the statements else loop is terminated. PL/SQL PROGRAM STRUCTURE -----------------------Plsql provides its program structure in the form of blocks that can be executed or called by any front end tool that supports plsql programming method.

The following are the types of blocks plsql provides : 1) Anonymous Block 2) Function 3) Procedure 4) Package 5) Trigger