web analytics

Oracle Identifiers

Options

codeling 1602 - 6666
@2016-10-03 16:02:19

You use identifiers to name PL/SQL program items and units, which include constants, variables, exceptions, cursors, cursor variables, subprograms, and packages. Some examples of identifiers follow:

X

t2

phone#

credit_limit

LastName

oracle$number

An identifier consists of a letter optionally followed by more letters, numerals, dollar signs, underscores, and number signs. Other characters such as hyphens, slashes, and spaces are not allowed, as the following examples show:

mine&yours -- not allowed because of ampersand

debit-amount -- not allowed because of hyphen

on/off -- not allowed because of slash

user id -- not allowed because of space

Adjoining and trailing dollar signs, underscores, and number signs are allowed:

money$$$tree

SN##

try_again_

You can use upper, lower, or mixed case to write identifiers. PL/SQL is not case sensitive except within string and character literals. If the only difference between identifiers is the case of corresponding letters, PL/SQL considers them the same:

lastname

LastName -- same as lastname

LASTNAME -- same as lastname and LastName

The size of an identifier cannot exceed 30 characters. Every character, including dollar signs, underscores, and number signs, is significant. For example, PL/SQL considers the following identifiers to be different:

lastname

last_name

Identifiers should be descriptive. Avoid obscure names such as cpm. Instead, use meaningful names such as cost_per_thousand.

@2016-10-03 16:03:27

Some identifiers, called reserved words, have a special syntactic meaning to PL/SQL. For example, the words BEGIN and END are reserved. Trying to redefine a reserved word causes a compilation error. Instead, you can embed reserved words as part of a longer identifier:

DECLARE
   -- end BOOLEAN;          -- not allowed; causes compilation error
   end_of_game BOOLEAN;  -- allowed
BEGIN
   NULL;
END;
/
@2016-10-03 16:05:23

Predefined Identifiers

Identifiers globally declared in package STANDARD, such as the exception INVALID_NUMBER, can be redeclared. However, redeclaring predefined identifiers is error prone because your local declaration overrides the global declaration.

@2016-10-03 16:06:01

Quoted Identifiers

For flexibility, PL/SQL lets you enclose identifiers within double quotes. Quoted identifiers are seldom needed, but occasionally they can be useful. They can contain any sequence of printable characters including spaces but excluding double quotes. Thus, the following identifiers are valid:

"X+Y"
"last name"
"on/off switch"
"employee(s)"
"*** header info ***"

The maximum size of a quoted identifier is 30 characters not counting the double quotes. Though allowed, using PL/SQL reserved words as quoted identifiers is a poor programming practice.

Comments

You must Sign In to comment on this topic.


© 2024 Digcode.com