Question about using subtypes (define a user-defined subtype w/ constrain)
763890May 8 2010 — edited May 12 2010Hi guys,
I am a newbie to PL/SQL.
I do really appreciate it if you would spare a bit of your time to reply this post.
According to the sub-section of Oracle® Database PL/SQL User's Guide and Reference 10g Release 2 (10.2) labeled Using Subtypes, I have found that the constrain of user-defined subtype can be overridden when declaring variables.
Qestions:
1. Why does PL/SQL allow constrain override of user-defined subtype? Or is it a unforeseen bug that exist in PL/SQL?
2. Does it happen to Oracle subtypes such as INTEGER, CHARACTER,etc.?
I have replicated this issue using the following PL/SQL code against Oracle9i 9.2.0.1, which produced no errors or exceptions whatsoever.
TO ELIMINATE ANY CONFUSIONS, THE ISSUE IN QUESTION IS HIGHLIGHTED IN BOLD
-- SAMPLE CODE TO REPLICATE THE ISSUE
DECLARE
-- a user-defined subtype(Xtype) is defined with a precision & scale constrain;
SUBTYPE Xtype IS NUMBER(1,0);
-- however, Xtype is overridden when declaring variable 'var_num'.
var_num Xtype(2,0);
BEGIN
var_num := 10;
DBMS_OUTPUT.PUT_LINE('var_num = ' || TO_CHAR(var_num));
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERR: ' || SQLERRM);
END;
/
-- HERE IS THE OUTPUT
SQL> @D:\LocalWork\dummy.sql
var_num = 10
Edited by: HappyJay on 2010/05/09 1:48