PL/SQL block structure: – PL/SQL is a block structure language, meaning that programs can be divided into logical blocks. These blocks describe process, which have to be applied to data. A single PL/SQL code block consist of a set of SQL statements clubbed together, and passed to the oracle engine entirely. If we create stored procedure or package, we give the block of PL/SQL code a name. if the block of PL/SQL code is not given a name, then it is called an anonymous block. PL/SQL block divided into four section. They are DECLARE section, BEGIN section, EXCEPTION section and END section. Out of four block, DECLARE and EXCEPTION are optional and BERIN and END block are mandatory. Function of these four blocks are –

  1. DECLARE: – The DECLARE word begins a PL/SQL block. This section used for variable declaration, curser definition and another oracle object can be declared. Once, these are declared, they can be used in SQL statement for data manipulation.
  2. BEGIN: – It is mandatory part of PL/SQL block. It consists of a set of the SQL statement to manipulate data in the data base and PL/SQL statement to manipulate data in the block. Actual data implementation, looping and branching are specified in this section.
  3. EXCEPTION: – This is an optional part and used for error handling. An error that arise during execution of data manipulation statement, which make up the PL/SQL code block. Errors can arise do to syntax, logic and/or validation rule violation.
  4. END: – It is mandatory part of Pl/SQL block. The keyword END terminated by semi colon sign (;).