If I create a view in Oracle, the column definition's not null characteristic is inherited from the base table:
create table tq84_t (
col_1 number,
col_2 varchar2(15) not null
);
create view tq84_v as select col_1, col_2 from tq84_t;
desc tq84_v;
will print
Name Null? Type
--------------- -------- -----------------------------------------
COL_1 NUMBER
COL_2 NOT NULL VARCHAR2(15)
Now, if the view's select statement contains a union all
, it seems as though that characteristic is not inherited anymore:
drop view tq84_v;
create view tq84_v as
select col_1, col_2 from tq84_t where col_1 < 10 union all
select col_1, col_2 from tq84_t where col_2 > 20;
desc tq84_v;
prints:
Name Null? Type
--------------- -------- -----------------------------------------
COL_1 NUMBER
COL_2 VARCHAR2(15)
This is a bit unfortunate for my purposes. So, is there a way to explicitely state that a column be not null
for a view in Oracle?
Note: I obviously used a simplified view defintion to demonstrate the problem, and I could re-write the view definition without using union all
. Yet, my actual view defintion is much more complicated, requiring the union all
.