Learn the purpose and how to unravel the ORA-01439 error message in Oracle.
Description
When you stumble upon an ORA-01439 error, the following error message will appear:
ORA-01439: column to be modified ought to be empty to trade datatype
Cause
You tried to execute a ALTER TABLE MODIFY declaration to exchange the datatype of a column, but the column contained data. You can solely modify the datatype of a column whose values are all NULL.
Resolution
The option(s) to resolve this Oracle error are:
Option #1
Execute an UPDATE declaration to alternate all values in that column to NULL.
Option #2
Execute a DELETE declaration to get rid of all rows from the table.
For example, if you had a desk referred to as suppliers described as follows:
CREATE TABLE suppliers
( supplier_id number(5),
supplier_name varchar2(50)
);
Then executed an INSERT statement as follows:
INSERT into suppliers
(supplier_id, supplier_name)
VALUES (12345, 'IBM');
And you tried to execute the following ALTER TABLE statement:
ALTER TABLE suppliers
MODIFY supplier_id varchar2(5);
You would receive the following error message:
You could right the error with either of the following solutions:
Solution #1
You can update the supplier_id column to all NULLs. This only works if the supplier_id discipline will be given NULL values.
UPDATE suppliers
SET supplier_id = NULL;
Solution #2
You can get rid of all entries from the suppliers table.
DELETE FROM suppliers;
If you do figure out to delete all entries from your suppliers table, you might desire to make sure that you have a backup of the data.
Leave a Review