| Oracle® Database PL/SQL Language Reference 11g Release 1 (11.1) Part Number B28370-05 |
|
|
View PDF |
A constant holds a value that does not change.
A constant declaration specifies its name, data type, and value, and allocates storage for it. The declaration can also impose the NOT NULL constraint.
Syntax
constant_declaration ::=

datatype ::=

Keyword and Parameter Descriptions
collection_name
A collection (associative array, nested table, or varray) previously declared within the current scope.
collection_type_name
A user-defined collection type defined using the data type specifier TABLE or VARRAY.
constant_name
The name of the constant. For naming conventions, see Identifiers.
cursor_name
An explicit cursor previously declared within the current scope.
cursor_variable_name
A PL/SQL cursor variable previously declared within the current scope.
db_table_name
A database table or view that must be accessible when the declaration is elaborated.
db_table_name.column_name
A database table and column that must be accessible when the declaration is elaborated.
expression
The value to be assigned to the constant when the declaration is elaborated. The value of expression must be of a data type that is compatible with the data type of the constant.
A constraint that prevents the program from assigning a null value to the constant. Assigning a null to a variable defined as NOT NULL raises the predefined exception VALUE_ERROR.
object_name
An instance of an object type previously declared within the current scope.
record_name
A user-defined or %ROWTYPE record previously declared within the current scope.
record_name.field_name
A field in a user-defined or %ROWTYPE record previously declared within the current scope.
record_type_name
A user-defined record type that is defined using the data type specifier RECORD.
ref_cursor_type_name
A user-defined cursor variable type, defined using the data type specifier REF CURSOR.
%ROWTYPE
Represents a record that can hold a row from a database table or a cursor. Fields in the record have the same names and data types as columns in the row.
scalar_datatype_name
A predefined scalar data type such as BOOLEAN, NUMBER, or VARCHAR2. Includes any qualifiers for size, precision, and character or byte semantics.
%TYPE
Represents the data type of a previously declared collection, cursor variable, field, object, record, database column, or variable.
Usage Notes
Constants are initialized every time a block or subprogram is entered. Whether public or private, constants declared in a package specification are initialized only once for each session.
You can define constants of complex types that have no literal values or predefined constructors, by invoking a function that returns a filled-in value. For example, you can make a constant associative array this way.
Related Topics