Posts

Showing posts from April, 2014

PL/SQL Block Structure

Image
The smallest meaningful grouping of code is known as a block. A block is a unit of code that provides execution and scoping boundaries for variable declarations and exception handling. PL/SQL allows you to create anonymous blocks (blocks of code that have no name) and named blocks, which may be packages, procedures, functions, triggers, or object types. A PL/SQL block has up to four different sections, only one of which is mandatory: Example:- --Header Section PROCEDURE myFirstProcedure(NAME IN Varchar2) IS --Declaration Section SALARY NUMBER; JOINING_DATE DATE; BEGIN --Execution Section INSERT INTO EMPLOYEE (emp_name, salary, joining_date) VALUES (name, salary, joining_date); EXCEPTION --Exception Section WHEN DUP_VAL_IN_INDEX THEN DBMS_OUTPUT.PUT_LINE ("Duplicate Value, Cannot Insert."); END; /