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!

Not Nullable columns on Views with Table Joins

user588235Feb 18 2014 — edited Feb 19 2014

I seem to have come across a problem and I'm not sure how to fix it.

I've got a view in the database that references 2 tables via a 'union'. The view works properly, but right now one of the developers here needs it modified so that a certain field is 'not null'.

The problem is, even though the fields in the underlying tables are 'not null', the result of the view is still nullable.

Example, If I do the following:

create table t1

(x varchar(1) not null,

y varchar(1));

/

create table t2

(x varchar(1) not null,

y varchar(1));

/

create or replace view v1 as

select x from t1

union

select x from t2

It creates the tables properly with the x field being 'not null':

desc t1

Name Null             Type  

----      --------            -----------

XNOT NULL VARCHAR2(1)
Y                         VARCHAR2(1)

However, the view leaves the X column as nullable:

desc v1

Name Null Type  

----      ----   -----------

X            VARCHAR2(1)

(The X should be 'not null' in the view)

If I create a view that just accesses one table there is no problem. It seems to be the union that is messing things up.

Is there a way to force the X column to be 'not null'?

I've done some searching, and I could use NVL but I couldn't get that to work.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2014
Added on Feb 18 2014
10 comments
1,194 views