While adding NOT NULL column into a table, the following error occurred:
SQL> Alter table TEST_TBL add NAME CHAR(12) NOT NULL; Alter table TEST_TBL add NAME CHAR(12) NOT NULL * ERROR at line 1: ORA-01758: table must be empty to add mandatory (NOT NULL) column
The workarounds could be either of the following:
1) Default value is given:
SQL> Alter table TEST_TBL add NAME CHAR(12) DEFAULT 'EMPTY' NOT NULL;
2) Remove NOT NULL:
SQL> Alter TEST_TBL add NAME CHAR(12);
3) Backup the table to another staging table, truncate the table and then add the NOT NULL column, insert the records back to the table from the staging table.