PL/SQL - Basic Syntax

PL/SQL - Basic Syntax - Comments - Program Units - First PLSQL program

Basic Syntax of a PL/SQL program is:


DECLARE
<declarations section>
BEGIN
<executable section>
EXCEPTION
<exception handling section>
END;


My 'First PL/SQL' Program:


DECLARE
v_message varchar2(20):= 'My first PLSQL program!';
BEGIN
dbms_output.put_line(v_message);
END;
/

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.

Delimiters

List of PL/SQL delimiters:
DelimiterDescription
+, -, *, /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

Comments

There are single-line and multi-line comments available in PL/SQL.

DECLARE
-- variable declaration
v_message varchar2(20):= 'My first PLSQL example!';
BEGIN
/*
* This is PL/SQL executable statement(s)
*/
dbms_output.put_line(message);
END;
/
<<<Previous                                                                                                                                                                                  Next>>>

Complete Tutorial

*/