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.
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.
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.
Symbol | Description |
---|---|
; | |
% | Percent sign: attribute indicator (cursor attributes like %ISOPEN and indirect declaration attributes like %ROWTYPE). Also used as multibyte wildcard symbol, as in SQL. |
_ | |
: | Colon: host variable indicator, such as :block.item in Oracle Forms |
** | |
< > and != | |
|| | |
<< and >> | |
<= and >= | |
:= | |
=> | |
-- | |
/* and */ |
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.
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.