Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Question about using subtypes (define a user-defined subtype w/ constrain)

763890May 8 2010 — edited May 12 2010
Hi 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
This post has been answered by damorgan on May 10 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2010
Added on May 8 2010
8 comments
1,515 views