w3resource
PL/SQL DataType Exercises

PL/SQL DataType: Program to show the uses of an unconstrained subtype, i.e., the same set of values as its base type

PL/SQL DataType: Exercise-7 with Solution

Write a PL/SQL program to show the uses of an unconstrained subtype, i.e., the same set of values as its base type.

Sample Solution:

PL/SQL Code:

SET SERVEROUTPUT ON
DECLARE
  SUBTYPE ac_bal IS NUMBER;

  chk_ac        ac_bal(6,2);
  sb_ac         ac_bal(8,2);
  depo_certificate  ac_bal(8,2);
  max_ins_amt  CONSTANT   ac_bal(8,2) := 300000.00;

  SUBTYPE ctr IS NATURAL;

  acno     ctr := 1;
  dep_amt     Ctr := 0;
  wth_amt  Ctr := 0;
  od_amt   Ctr := 0;

  PROCEDURE ac_deposit (
    acbal  IN OUT ac_bal,
    amt   IN     ac_bal
  ) IS
  BEGIN
    acbal  := acbal + amt;
    dep_amt := dep_amt + 1;
  END;
  
BEGIN
  NULL;
END;
/

Flowchart:

Flowchart: PL/SQL DataType - Program to show the uses of an unconstrained subtype, i.e., the same set of values as its base type

In the above example the unconstrained subtypes ac_bal and ctr show the intended uses of data items of their types. The datatype of chk_ac, sb_ac, depo_certificate and the max_ins_amt are same datatype as the ac_bal and the datatype of acno, dep_amt, wth_amt and od_amt are same datatype as datatype ctr.

Improve this sample solution and post your code through Disqus

Previous: Write a PL/SQL program to show the uses of SIMPLE_INTEGER datatype.
Next:  Write a PL/SQL program to show the uses of a constrained subtype.

What is the difficulty level of this exercise?