Pages

Pages

Declaring PL/SQL Variables.

Declaring PL/SQL Variables:
Syntax
Identifier name [CONSTRAINT] datatype [NOT NULL] [:=DEFAULT]  Expr;
 

Identifier name:
  • Specifies the name of the relevant variable for that block.
Constant:
  • Constant the variable such that its value cannot change during the program process.
  • Constants must be initialized else raise an exception.
Datatype:
  • It is a scalar, composite , reference of  LOB data type as applicable to the required situation.
NOTNULL:
  • Constraints a variable such that it must contain a value and raises if NULL is identified.
  • NOT NULL variables should be initialized else raise an exception.
Default:
  • Sets the default value for the value in the PL/SQL program if not attended.
Expr:
  • It is any PL/SQL expression that can be a literal, another variable or an expression involving operations and functions for initialization.

Illustration:
 

DECLARE
     Vno number(4):= 7788;
     Vname varchar2(20) not null:=’SCOTT’;
            --must not hold null value through out program
     Doj date default sysdate;
     Flag Boolean:=true;
            --for Boolean variable accept only TRUE or FALSE value and value should not be in single code.

     pcode constant number(6):=567892;
           --cannot be used as an assignment target.


 Click here to go to Back page

No comments:

Post a Comment