Using Declaring Variables in Oracle

This article is written about how to declare variables in Oracle/PLSQL with syntax and examples.

What is a variable in Oracle?

In Oracle/PLSQL, a variable approves a programmer to store records quickly for the duration of the execution of code.

Syntax

The syntax for declaring variables in Oracle is:

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

Parameters or Arguments

variable_name The identify to assign to the variable. CONSTANT Optional. If specified, the variable’s fee is consistent and can no longer be changed. datatype The datatype to assign to the variable.

Example – Declaring a variable

Below is an example of how to declare a variable in Oracle referred to as LDescription.

LDescription varchar2(40);

You can then later set or exchange the fee of the LDescription variable, as follows:

LDescription := 'techonthenet.com Example';

Example – Declaring a variable with an preliminary value (not a constant)

Below is an instance of how to declare a variable in Oracle and provide it an preliminary value. This is unique from a consistent in that the variable’s value can be modified later.

LType varchar2(40) := 'techonthenet.com Example';

You should later change the variable’s value, as follows:

LType := 'My value has changed';

Example – Declaring a constant

Below is an instance of how to declare a constant in Oracle. The price of a regular can not be changed.

LTotal CONSTANT numeric(8,1) := 8363934.1;