variables in PL/SQL

 What are variables?

   v Variables are place holder in computer memory that holds some data. We can call them variables because which can be changed any point in your program.

   v Every variable must have a valid name, a data type and a data width.

   v In PL/SQL every variable must be declared prior to its use and the declaration of the variables or even other objects can only be done in the declaration section of the PL/SQL block.

There are two ways assigning the value in PL/SQL:

Example: 1

  1. DECLARE

       v_var   VARCHAR2 (50) := 'Welcome to PL/SQL';

    BEGIN

       DBMS_OUTPUT.put_line (v_var);

    END;

Explanation:

   §  V_var is the variable name, the datatype of the variable VARCHAR and the width is 50.

   §  := is the assignment operator for assigning value into the variable.

   §  'Welcome to PL/SQL' is the value must be enclosed with single quotes (‘’)

   §  In this example we DECLARING and INITIALIZING the variable in DECLARE section.

Output:

Example: 2

  1. DECLARE

       v_var   VARCHAR2 (50);

    BEGIN

       v_var := 'Welcome';

       DBMS_OUTPUT.put_line (v_var);

    END;

Explanation:

 v We were initializing the variable in the BEGIN Section.

 Output:



 

Share:

No comments:

Post a Comment

Popular Posts

Search This Blog

Powered by Blogger.

Blog Archive

Service Support

Need our help to Learn or Post New Concepts Contact me

Blog Archive

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me