#

| Chapter 2 |

# 2. PL/SQL Language Fundamentals

Contents:
The PL/SQL Character Set
Identifiers
Literals
The Semicolon Delimiter
Comments
The PRAGMA Keyword
Block Structure

Every language -- whether human or computer -- has a syntax, vocabulary, and character set. In order to communicate within that language, you have to learn the rules that govern its usage. Many of us are very wary of learning a new computer language. Change is often scary, but, in general, programming languages are very simple tongues, and PL/SQL is a relatively simple programming language. The difficulty we have conversing in languages based on bytes is not with the language, but with the compiler or computer with which we are having the discussion. Compilers are, for the most part, very stupid. They are not creative, sentient beings. They are not capable of original thought. Their vocabulary is severely limited. Compilers just happen to think their dull thoughts very, very rapidly -- and very inflexibly.

If I hear someone ask "gottabuck?", I can readily interpret that sentence and decide how to respond. If I instruct PL/SQL, on the other hand, to "gimme the next half-dozen records," I will not get very far in my application. To use the PL/SQL language, you must dot your i's and cross your t's -- syntactically speaking. So, in this chapter, I cover the fundamental language rules that will help you converse with the PL/SQL compiler -- the PL/SQL character set, lexical units, PRAGMA keyword, and block structure.

## 2.1 The PL/SQL Character Set

A PL/SQL program consists of a sequence of statements, each of which is made up of one or more lines of text. Text is made up of combinations of the characters shown in Table 2.1.

Table 2.1: PL/SQL Character Set
Type | Characters
--- | ---
Letters | A-Z, a-z
Digits | 0-9
Symbols | ~ ! @ # $ % & * ( ) _ - + = | [ ] { } : ; " ' < > , . ? /
Whitespace | Tab, space, carriage return

Note that PL/SQL is a case-insensitive language. Uppercase letters are treated the same way as lowercase letters except when the characters are surrounded by single quotes (when they are literal strings) or represent the value of a character variable.

Every valid statement in PL/SQL, from declaration to executable statement to keyword, is made up of various combinations of the above characters. Now you just have to figure out how to put them all together!

A number of these characters -- both singly and in combination with other characters -- have a special significance in PL/SQL. Table 2.2 lists these special symbols.

Table 2.2: Simple and Compound Symbols in PL/SQL
Symbol | Description
--- | ---
; | Semicolon: statement terminator
% | Percent sign: attribute indicator (cursor attributes like %ISOPEN and indirect declaration attributes like %ROWTYPE). Also used as multibyte wildcard symbol, as in SQL.
_ | Single underscore: single-byte wildcard symbol, as in SQL
: | Colon: host variable indicator, such as :block.item in Oracle Forms
** | Double asterisk: exponentiation operator
< > and != | "Not equals"
|| | Double vertical bar: concatenation operator
<< and >> | Label delimiters
<= and >= | Relational operators
:= | Assignment operator
=> | Association operator for positional notation
-- | Double dash: single-line comment indicator
`/*` and `*/` | Beginning and ending multiline comment block delimiters

Characters are grouped together into lexical units, also called atomics of the language, because they are the smallest individual components. A lexical unit in PL/SQL is any of the following:

- Identifier

- Literal

- Delimiter

- Comment

These are described in the following sections.

1.7 Best Practices for PL/SQL Excellence |  | 2.2 Identifiers

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.