Table with virtual columns
create table tq84_virt_col_t (
dt_start date,
dt_end date,
days as ( dt_end - dt_start )
);
insert into tq84_virt_col_t(dt_start, dt_end) values (date '2022-03-05', date '2022-05-16');
select * from tq84_virt_col_t;
Table with default values
create table tq84_def_col_t (
id number(5),
default_val date default sysdate
);
insert into tq84_def_col_t (id) values (1);
select
*
from
tq84_def_col_t;
Querying virtual columns from the data dictionary
The expression that provides the value for a virtual column
and default values can be queried from the column
data_default
in the
data dictionary's view
dba_tab_cols
.
The value of virtual_column
(YES
or NO
) determines if data_default
is a default expression or not.
select
obj.object_type,
obj.owner,
col.table_name,
col.column_name,
col.data_default,
col.virtual_column,
col.*
from
dba_objects obj join
dba_tab_cols col on obj.owner = col.owner and
obj.object_name = col.table_name
where
-- obj.oracle_maintained = 'N' and
col.table_name in ('TQ84_VIRT_COL_T', 'TQ84_DEF_COL_T') and
col.owner = user
;