For Full Course Experience Please Go To
Full Course Experience Includes
1. Access to course videos and exercises
2. View & manage your progress/pace
3. In-class projects and code reviews
4. Personal guidance from your Mentors
Goal is to write your first PL/SQL program.
The basic program unit in PL/SQL is the block. A PL/SQL block is defined by the keywords DECLARE, BEGIN, EXCEPTION, and END. These keywords partition the block into a declarative part, an executable part, and an exception-handling part.
Example of a Block
emp_id NUMBER(6) := 100;
SELECT salary * 0.10 INTO bonus
WHERE employee_id = emp_id;
When NO_DATA_FOUND THEN
This is a typical PL/SQL block where 10% of salary is selected and stored on a temp variables bonus. If for some reason there is no employee with empid = 100 then the control will come to exception area and the code in the exception area will be executed.
These blocks can be entirely separate or nested one within another. The basic units (procedures and functions, also known as subprograms, and anonymous blocks) that make up a PL/SQL program are logical blocks, which can contain any number of nested sub blocks. Therefore, one block can represent a small part of another block, which in turn can be part of the whole unit of code.
Anonymous blocks are unnamed blocks. They are declared at the point in an application where they are to be executed and are passed to the PL/SQL engine for execution at run time. You can embed an anonymous block within a pre-compiler program and within iSQL*Plus or Server Manager. Triggers in Oracle Developer components consist of such blocks.
Subprograms are named PL/SQL blocks that can accept parameters and can be invoked. You can declare them either as procedures or as functions. Generally use a procedure to perform an action and a function to compute a value.
You can store subprograms at the server or application level. Using Oracle Developer components (Forms, Reports, and Graphics), you can declare procedures and functions as part of the application (a form or report) and call them from other procedures, functions, and triggers (see next page) within the same application whenever necessary.
Note: A function is similar to a procedure, except that a function must return a value.