Declaring PL/SQL Variables.
0
Declaring PL/SQL Variables:
Syntax
Identifier name [CONSTRAINT] datatype [NOT NULL] [:=DEFAULT] Expr;
Identifier name:
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.
Syntax
Identifier name [CONSTRAINT] datatype [NOT NULL] [:=DEFAULT] Expr;
Identifier name:
- Specifies the name of the relevant variable for that block.
- Constant the variable such that its value cannot change during the program process.
- Constants must be initialized else raise an exception.
- It is a scalar, composite , reference of LOB data type as applicable to the required situation.
- 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.
- Sets the default value for the value in the PL/SQL program if not attended.
- 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.
0 comments: