I'm trying to figure out when the use of the RANGE clause is allowed in variable definition within the declarative section of a PL/SQL block.
The following code was tested on Oracle 12c
This works...
declare
l_constrained PLS_INTEGER RANGE 7..10 ;
begin
l_constrained := 9;
end ;
/
This gives a compilation error...
declare
l_constrained NUMBER(2) RANGE 7..10 ;
begin
l_constrained := 9;
end ;
/
It seems to work only when applied to PL/SQL data types and not with SQL data types, but that's just my first impression.
Could anybody please give me some info and possibly head me to Oracle's official documentation covering the use of the RANGE clause? I cannot find it...
Never even heard of this feature before.
Anyway, this seems to be called a "constrained subtype" and work only with PLS_INTEGER
and subsets.
The only base types for which you can specify a range of values are PLS_INTEGER and its subtypes (both predefined and user-defined).
https://docs.oracle.com/database/121/LNPLS/datatypes.htm#CHDBBCIE
The documentation doesn't explicitly mention RANGE
usage outside of subtype declaration, but I guess it somehow falls into the same category as declaring variable as NUMBER(8,2)
, i.e. declaring with a constraint on a type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With