Your browser does not support JavaScript. This help page requires JavaScript to render correctly. Declaring and Assigning Values to Variables and Constants
Skip Headers
Previous
Previous
 
Next
Next

Declaring and Assigning Values to Variables and Constants

One significant advantage that PL/SQL has over SQL is that PL/SQL lets you declare and use variables and constants.

A variable or constant declared in a package specification can be used by any program that has access to the package. A variable or constant declared in a package body or subprogram is local to that package or subprogram.

A variable holds a value of a particular data type. Your program can change the value at run time. A constant holds a value that cannot be changed.

A variable or constant can have any PL/SQL data type. When declaring a variable, you can assign it an initial value; if you do not, its initial value is NULL. When declaring a constant, you must assign it an initial value. To assign an initial value to a variable or constant, use the assignment operator (:=).


Tip:

Declare all values that do not change as constants. This practice optimizes your compiled code and makes your source code easier to maintain.

This section contains:

Related Topics

Oracle Database PL/SQL Language Reference

Developing Stored Subprograms and Packages