PL/SQL is the Oracle Procedural Language extension of SQL..
A PL/SQL program can have both SQL and statement and procedural statements. In the PL/SQL program, SQL is used to access sets of data stored in a database ,while the procedural statements are used to process individual piece of data and control the program flow.
PL/SQL programs are divided and written in logical blocks of code. Each block consists of three sub-parts −
| Sl.No | Sections & Description |
|---|---|
| 1 | Declarations This section starts with the keyword DECLARE. It is an optional section and defines all variables, cursors, subprograms, and other elements to be used in the program. |
| 2 | Executable Commands This section is enclosed between the keywords BEGIN and END and it is a mandatory section. It consists of the executable PL/SQL statements of the program. It should have at least one executable line of code, which may be just a NULL command to indicate that nothing should be executed. |
| 3 | Exception Handling This section starts with the keyword EXCEPTION. This optional section contains exception(s) that handle errors in the program. |
The PL/SQL Identifiers
PL/SQL identifiers are constants, variables, exceptions, procedures, cursors, and reserved words. The identifiers consist of a letter optionally followed by more letters, numerals, dollar signs, underscores, and number signs and should not exceed 30 characters.
By default, identifiers are not case-sensitive. So you can use integer or INTEGER to represent a numeric value. You cannot use a reserved keyword as an identifier.
The PL/SQL Delimiters
A delimiter is a symbol with a special meaning. Following is the list of delimiters in PL/SQL −
|
Delimiter |
Description |
|
+, -, *, / |
Addition, subtraction/negation,
multiplication, division |
|
% |
Attribute indicator |
|
' |
Character string delimiter |
|
. |
Component selector |
|
(,) |
Expression or list delimiter |
|
: |
Host variable indicator |
|
, |
Item separator |
|
" |
Quoted identifier delimiter |
|
= |
Relational operator |
|
@ |
Remote access indicator |
|
; |
Statement terminator |
|
:= |
Assignment operator |
|
=> |
Association operator |
|
|| |
Concatenation operator |
|
** |
Exponentiation operator |
|
<<, >> |
Label delimiter (begin and end) |
|
/*, */ |
Multi-line comment delimiter
(begin and end) |
|
-- |
Single-line comment indicator |
|
.. |
Range operator |
|
<, >, <=, >= |
Relational operators |
|
<>, '=, ~=, ^= |
Different versions of NOT EQUAL |
The PL/SQL Comments
Program comments are explanatory statements that can be included in the PL/SQL code that you write and helps anyone reading its source code. All programming languages allow some form of comments.
The PL/SQL supports single-line and multi-line comments. All characters available inside any comment are ignored by the PL/SQL compiler. The PL/SQL single-line comments start with the delimiter -- (double hyphen) and multi-line comments are enclosed by /* and */.
PL/SQL Program Units
A PL/SQL unit is any one of the following −
- PL/SQL block
- Function
- Package
- Package body
- Procedure
- Trigger
- Type
- Type body
No comments:
Post a Comment