PL/SQL DataType: Program to show the uses of a constrained subtype
PL/SQL DataType: Exercise-8 with Solution
Write a PL/SQL program to show the uses of a constrained subtype.
Sample Solution:
PL/SQL Code:
Sample Output:
The value assigned is:8
Flowchart:
In the above example, a subtype is created using the BINARY_INTEGER data type, but with the restriction on the values allowed by using the range keyword. When the variable is assigned with a value outside its range, the unit fails with a VALUE_ERROR. In this example the value is within the range, so no value_error appear.
Now modi the value and see the result-
Flowchart:
Sample Output:
DECLARE * ERROR at line 1: ORA-06502: PL/SQL: numeric or value error ORA-06512: at line 7
In this example the value exceeds the range, and the value_error appear.
Improve this sample solution and post your code through Disqus
Previous: Write a PL/SQL program to show the uses of an unconstrained subtype, i.e., the same set of values as its base type.
Next: PL/SQL Fundamentals Home.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics