How to use Declare Variables in PL/SQL In SQL
Syntax:
DECLARE
variable_name datatype := initial_value;
In this syntax,
- variable_name: It is the name of the variable.
- datatype: It is the data type of the variable.
- := initial_value: It is an optional assignment of an initial value to the variable.
Example:
DECLARE
name VARCHAR2(20) := 'w3wiki';
BEGIN
DBMS_OUTPUT.PUT_LINE(name);
END;
Output:
Explanation: In the above Query, We have declares a variable named “name” with a size of 20 characters and initializes it with the value w3wiki then prints the value of the variable using DBMS_OUTPUT.PUT_LINE.
How to Declare a Variable in PL/SQL?
Declaring variables in PL/SQL is a fundamental step towards building powerful and efficient database applications. Variables act as placeholders for data which enable us to manipulate and store information within our PL/SQL programs.
Understanding how to declare variables is essential for writing effective and scalable code. In this article, we will learn about how to declare a variable with the help of various methods along with the syntax and examples.
Contact Us