24. 1. 1. Writing a simple program |
|
The simplest kind of PL/SQL code is called an anonymous block. |
An anonymous block is a block of code that has its own DECLARE/BEGIN/END structure. |
Anonymous blocks can either stand on their own (as shown here) or they can sit within any other PL/SQL program. |
The general syntax for an anonymous block: |
declare
...
<Declaration part>
...
begin
...
<Procedural part>
...
exception
...
<Exception handler>
...
end;
|
|
- The declaration section defines all variables, cursors, subprograms, and other elements to be used in the code.
- The declaration section is optional.
- The procedural section contains the main body of the routine.
- The procedural section starts with the begin keyword and ends with the exception keyword or the end keyword if you have no exception section.
- The procedural section is the only mandatory part of the code.
- You must have at least one line of executable code in the procedural section.
- You can use the NULL command to indicate that nothing should be executed.
- The exception section is also optional.
- The exception section allows the program to intercept and process exceptions.
|