It's very likely that you, as @Rob correctly pointed out, assigned NULL
as a default value for a column.
Unfortunately, you cannot remove once assigned default value for a column - the data_default
column of user_tab_columns
data dictionary view will always contain data.
Note: If a column has a default value, then you can use the DEFAULT
clause to change the default to NULL, but you cannot remove the
default value completely. If a column has ever had a default value
assigned to it, then the DATA_DEFAULT column of the USER_TAB_COLUMNS
data dictionary view will always display either a default value or
NULL.
If you want this condition DATA_DEFAULT IS NOT NULL
to succeed, the only option is to recreate the column without default
clause.
- create a new column
- Copy data from the damaged one
- Drop the column, which has been created with
default
clause
- Rename the newly created column.
Example:
create table TB_Test(
col number default null
);
insert into tb_test(col)
select level
from dual
connect by level <= 11;
select column_name,
data_default,
data_type
from user_tab_columns
where table_name = upper('tb_test')
and data_default is not null
Column_Name Data_Default Data_Type
--------------------------------------
COL null NUMBER
^
|
string literal
SQL> alter table tb_test add col2 number;
Table altered
update tb_test
set col2 = col
SQL> alter table tb_test drop column col;
Table altered
SQL> alter table tb_test rename column col2 to col;
Table altered
select column_name,
data_default,
data_type
from user_tab_columns
where table_name = upper('tb_test')
and data_default is not null
no rows selected