By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table t (x int, y int, z int)
insert into t (x) values (1)
1 rows affected
select * from t
X | Y | Z |
---|---|---|
1 | null | null |
alter table t modify y default 0
select * from t
X | Y | Z |
---|---|---|
1 | null | null |
insert into t(x) values (2)
1 rows affected
insert into t(x, y) values (2, null)
1 rows affected
select * from t
X | Y | Z |
---|---|---|
1 | null | null |
2 | 0 | null |
2 | null | null |
alter table t add y_notnull generated always as (coalesce(y, 0));
select * from t
X | Y | Z | Y_NOTNULL |
---|---|---|---|
1 | null | null | 0 |
2 | 0 | null | 0 |
2 | null | null | 0 |
alter table t modify y not null
ORA-02296: cannot enable (FIDDLE_SIOJVQZSOPYVAUCGWGHX.) - null values found
update t set y = -1 where y is null
2 rows affected
alter table t modify y not null
select * from t
X | Y | Z | Y_NOTNULL |
---|---|---|---|
1 | -1 | null | -1 |
2 | 0 | null | 0 |
2 | -1 | null | -1 |