Saturday, 21 October 2017

Constant In PL/SQL

  •  We are using CONSTANT part of a PL/SQL declaration.
  •  A constant is declared using the CONSTANT keyword.
  •  CONSTANT requires an initial value.
  •  CONSTANT remains unchanged throughout the program.

Syntax :
 constant_name CONSTANT datatype := VALUE;

Example:
 If you want to write a program which will calculate the interest of the bank. Bank interest we can declare  and we use it throughout in our program. If the interest got change then we need to change the CONSTANT value no need to change throughout the program.

CONSTANT remains unchanged throughout the program:

DECLARE
  v_string  VARCHAR2(20);
  n_number  NUMBER(10);
  v_con_string CONSTANT VARCHAR2(20) := 'oracleguide4u';
 BEGIN
  v_string := 'oracleguide';
  n_number := 1;
  v_con_string := 'This will fail';
  *
ERROR at line 10:
ORA-06550: line 10, column 3:
PLS-00363: expression 'V_CON_STRING' cannot be used as an assignment target



 DECLARE
  v_string  VARCHAR2(20);
  n_number  NUMBER(10);
  v_con_string CONSTANT VARCHAR2(20) := 'oracleguide4u';
 BEGIN
  v_string := 'oracleguide';
  n_number := 1;
 END;



No comments:

Post a Comment