PL/SQL User's Guide and Reference Release 2 (9.2) Part Number A96624-01 |
|
PL/SQL Language Elements, 11 of 52
You can declare constants and variables in the declarative part of any PL/SQL block, subprogram, or package. Declarations allocate storage space for a value, specify its datatype, and name the storage location so that you can reference it. Declarations can also assign an initial value and impose the NOT
NULL
constraint. For more information, see "Declarations".
Identifies a collection (index-by table, nested table, or varray) previously declared within the current scope.
Identifies a user-defined collection type that was defined using the datatype specifier TABLE
or VARRAY
.
Denotes the declaration of a constant. You must initialize a constant in its declaration. Once initialized, the value of a constant cannot be changed.
Identifies a program constant. For naming conventions, see "Identifiers".
Identifies an explicit cursor previously declared within the current scope.
Identifies a PL/SQL cursor variable previously declared within the current scope.
A database table or view that must be accessible when the declaration is elaborated.
A database table and column that must be accessible when the declaration is elaborated.
An arbitrarily complex combination of variables, constants, literals, operators, and function calls. The simplest expression consists of a single variable. When the declaration is elaborated, the value of expression
is assigned to the constant or variable. The value and the constant or variable must have compatible datatypes.
This constraint prevents the assigning of nulls to a variable or constant. At run time, trying to assign a null to a variable defined as NOT
NULL
raises the predefined exception VALUE_ERROR
. The constraint NOT
NULL
must be followed by an initialization clause.
Identifies an instance of an object type previously declared within the current scope.
Identifies a user-defined or %ROWTYPE
record previously declared within the current scope.
Identifies a field in a user-defined or %ROWTYPE
record previously declared within the current scope.
Identifies a user-defined record type that is defined using the datatype specifier RECORD
.
Identifies a user-defined cursor variable type is was defined using the datatype specifier REF
CURSOR
.
This attribute provides a record type that represents a row in a database table or a row fetched from a previously declared cursor. Fields in the record and corresponding columns in the row have the same names and datatypes.
Identifies a predefined scalar datatype such as BOOLEAN
, NUMBER
, or VARCHAR2
. Includes any qualifiers for size, precision, or character versus byte semantics.
This attribute provides the datatype of a previously declared collection, cursor variable, field, object, record, database column, or variable.
Identifies a program variable.
Constants and variables are initialized every time a block or subprogram is entered. By default, variables are initialized to NULL
. So, unless you expressly initialize a variable, its value is undefined.
Whether public or private, constants and variables declared in a package spec are initialized only once for each session.
An initialization clause is required when declaring NOT
NULL
variables and when declaring constants. If you use %ROWTYPE
to declare a variable, initialization is not allowed.
Several examples of variable and constant declarations follow:
credit_limit CONSTANT NUMBER := 5000; invalid BOOLEAN := FALSE; acct_id INTEGER(4) NOT NULL DEFAULT 9999; pi CONSTANT REAL := 3.14159; postal_code VARCHAR2(20); last_name VARCHAR2(20 CHAR); my_ename emp.ename%TYPE;
"Declarations", "Predefined Datatypes", Assignment Statement, Expressions, %ROWTYPE Attribute, %TYPE Attribute
|
Copyright © 1996, 2002 Oracle Corporation. All Rights Reserved. |
|