Skip Headers
Oracle® Database PL/SQL Language Reference
11g Release 2 (11.2)

Part Number E10472-05
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Constant

A constant holds a value that does not change.

A constant declaration specifies the name, data type, and value of the constant and allocates storage for it. The declaration can also impose the NOT NULL constraint.

Topics:

Syntax

constant_declaration ::=

constant_declaration
Description of the illustration constant_declaration.gif

See expression ::=.

datatype ::=

datatype
Description of the illustration datatype.gif

Semantics

constant_declaration

constant_name

The name of the constant that you are declaring.

NOT NULL

Prevents the program from assigning the value NULL to the constant.

PL/SQL subtypes NATURALN, POSITIVEN, and SIMPLE_INTEGER are predefined as NOT NULL. When declaring a constant of one of these subtypes, you can omit NOT NULL.

If you declare a NOT NULL constant, either by specifying NOT NULL or by specifying a subtype that is predefined as NOT NULL, you must also specify an initial value for the constant.

expression

The initial value for the constant. The value of expression must have a data type that is compatible with datatype (see Table 3-10, "Possible Implicit PL/SQL Data Type Conversions"). When constant_declaration is elaborated, the value of expression is assigned to constant_name.

datatype

collection_name

The name of a collection.

collection_type_name

The name of a user-defined collection type defined with the data type specifier TABLE or VARRAY.

cursor_name

The name of an explicit cursor.

cursor_variable_name

The name of a cursor variable.

db_table_name

The name of a database table or view, which must be accessible when the declaration is elaborated.

column_name

The name of a column of the database table or view db_table_name.

object_name

An instance of a user-defined type.

object_type_name

The name of a user-defined type.

record_name

The name of a record.

field_name

The name of a field of record_name.

record_type_name

The name of a user-defined type that was defined with the data type specifier RECORD.

ref_cursor_type_name

The name of a user-defined type that was defined with the data type specifier REF CURSOR.

scalar_datatype_name

The name of a predefined scalar data type, including any qualifiers for size, precision, and character or byte semantics. For information about predefined scalar data types, see "Predefined PL/SQL Scalar Data Types and Subtypes".

variable_name

The name of a variable.

Examples

Related Topics

In this chapter:

In other chapters: