Skip to Main Content

Developer Community

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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Create View using subtr causing column size 4 x larger

David PateyApr 15 2025 — edited Apr 16 2025

Hi

I was using substr when creating a view as the source table (not my table) has all columns set to varchar2(2000). This cuases issues in SAS for our Stats team.

When I use substr in my create script, the column sizes are coming out to be 4 times larger than the substr params.

example:

Source table:

CREATE TABLE Dave_test
( Test1 varchar2(100)
,test2 varchar2(100)
,test4 varchar2(500)
,test3 number);

View script:

CREATE OR REPLACE VIEW davetest_vw
AS SELECT SUBSTR(Test1,1,10) AS test1
,SUBSTR(test2,1,20) AS test2
,SUBSTR(test4,1,200) AS test4
FROM Dave_test;

Gives me:

SQL> desc davetest_vw
Name Null? Type
----------------------------------------- -------- ----------------------------
TEST1 VARCHAR2(40)
TEST2 VARCHAR2(80)
TEST4 VARCHAR2(800)

Now, I have done my research and know the main solution is replacing substr with a CAST… CAST(TEST1 as VARCHAR2(10))

but I would like to know WHY does the substr multiple the specified size by 4?? I hate no knowing why it does this… lol

Thanks,

Dave

Comments
Post Details
Added on Apr 15 2025
0 comments
136 views