Posted on Sunday, 6th September 2009 by captainmi2

You can declare variables and constants 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.

Variables can have any SQL datatype, such as CHAR, DATE, or NUMBER, or a PL/SQL-only datatype, such as BOOLEAN or PLS_INTEGER.

How to declare variable in Oracle PL\SQL

syntax:
variable_name [CONSTANT] datatype [NOT NULL] [:= | DEFAULT initial_value]

see example below:


declare
blood_type CHAR := 'O';
acct_id INTEGER(4) NOT NULL := 9999;
result varchar2(100);
created_date date;
n_days CONSTANT NUMBER := 200;

begin
........
end;

You can also declare nested tables, variable-size arrays (varrays for short), and records using the TABLE, VARRAY, and RECORD composite datatypes.

Posted in Basic, Oracle | Comments (0)

Leave a Reply