RelationalDBDesign
RedhatLinuxSys Seomining
prev next prev next
  Course navigation
 
Lesson 2
Objective
PL/SQL block guidelines
Describe the basic structure of a PL/SQL block.
   
A standard PL/SQL code segment is called a block.
Unlike SQL, PL/SQL allows logical grouping of a set of statements that can be sent to the Oracle database as a single block.
Block structure
Conceptually, a block can consist of three parts, or sections:
  1. An optional declaration section, where you can declare variables, constants, and exceptions
  2. A required section of executable statements
  3. An optional section of exception handlers
The order of the blocks in the code segment is logical. Blocks begin with the declarative part, where you declare the constants, variables, records, cursors, or exceptions. Once these are declared, you can manipulate them to build your program logic within the executable section.
Exceptions raised during execution can be dealt with in the exception handling section. A single exception handler is processed before the PL/SQL block is exited.
Each block can contain nested blocks. You will learn about nested blocks in the next lesson.
Block usage
Typically, a PL/SQL block must contain DECLARE, BEGIN, and END keywords. However, it may also include EXCEPTION keywords, where you can handle any exceptions for your block. Use the following SlideShow to see the order in which these sections appear within a block.
Image

Building pl sql block
In the next lesson, you will learn about nested blocks.
  Course navigation