Oracle 23.26Data typesLab-verified · 2026-11-25

ORA-01439: column to be modified must be empty to change datatype

ALTER TABLE ... MODIFY tried to change the data type of a column that still holds data.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-01439: column to be modified must be empty to change datatype

Jump to a cause

  1. 01Changing a VARCHAR2 column that holds numbers to NUMBER
  2. 02Changing a NUMBER column with yyyymmdd values to DATE
  3. 03Changing a NUMBER column to VARCHAR2 (e.g. zip codes)

Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-25 · container image gvenzl/oracle-free:23-slim

Oracle lets you change a column's data type with ALTER TABLE ... MODIFY only while every value in that column is NULL. If the column has data, the statement fails with ORA-01439 and nothing changes.

The usual way out is to add a new column with the type you want, copy the values over with a conversion function, drop the old column and, if needed, rename the new one. The three cases below were all run that way (or by emptying the column first) on a real database.

01Changing a VARCHAR2 column that holds numbers to NUMBER

orders.amount was VARCHAR2(20) holding '15000' and '320'. ALTER TABLE orders MODIFY (amount NUMBER) failed with ORA-01439, even though every value looked like a number.

The fix: ADD (amount_num NUMBER), UPDATE orders SET amount_num = TO_NUMBER(amount), commit, DROP COLUMN amount, then RENAME COLUMN amount_num TO amount. Afterwards user_tab_columns showed AMOUNT NUMBER, and amount * 2 returned 30000 and 640.

Setup
Setuprun as lab_a
CREATE TABLE orders (order_id NUMBER, amount VARCHAR2(20));
INSERT INTO orders VALUES (1001, '15000');
INSERT INTO orders VALUES (1002, '320');
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
ALTER TABLE orders MODIFY (amount NUMBER);
✕ ERROR
ALTER TABLE orders MODIFY (amount NUMBER)
                           *
ERROR at line 1:
ORA-01439: column to be modified must be empty to change datatype
Help: https://docs.oracle.com/error-help/db/ora-01439/
Fixrun as lab_a
ALTER TABLE orders ADD (amount_num NUMBER);
UPDATE orders SET amount_num = TO_NUMBER(amount);
COMMIT;
ALTER TABLE orders DROP COLUMN amount;
ALTER TABLE orders RENAME COLUMN amount_num TO amount;
OUTPUT
Table altered.


2 rows updated.


Commit complete.


Table altered.


Table altered.

The converted values go into a separate column first, so the old column is dropped only after the copy has succeeded and been committed.

After the fixrun as lab_a
COLUMN data_type FORMAT A12
SELECT column_name, data_type FROM user_tab_columns WHERE table_name = 'ORDERS' ORDER BY column_id;
SELECT order_id, amount, amount * 2 AS doubled FROM orders ORDER BY order_id;
✓ SUCCESS
COLUMN_NAME                    DATA_TYPE
------------------------------ ------------
ORDER_ID                       NUMBER
AMOUNT                         NUMBER

2 rows selected.


  ORDER_ID     AMOUNT    DOUBLED
---------- ---------- ----------
      1001      15000      30000
      1002        320        640

2 rows selected.

02Changing a NUMBER column with yyyymmdd values to DATE

Hire dates were stored as hire_ymd NUMBER(8) (20240301, 20251115). ALTER TABLE emp MODIFY (hire_ymd DATE) failed with ORA-01439.

A new hire_date DATE column was added and filled with TO_DATE(TO_CHAR(hire_ymd), 'YYYYMMDD'). After dropping hire_ymd, the table returned 2024-03-01 and 2025-11-15.

Setup
Setuprun as lab_a
CREATE TABLE emp (emp_id NUMBER, name VARCHAR2(20), hire_ymd NUMBER(8));
INSERT INTO emp VALUES (1, 'KIM', 20240301);
INSERT INTO emp VALUES (2, 'LEE', 20251115);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
ALTER TABLE emp MODIFY (hire_ymd DATE);
✕ ERROR
ALTER TABLE emp MODIFY (hire_ymd DATE)
                        *
ERROR at line 1:
ORA-01439: column to be modified must be empty to change datatype
Help: https://docs.oracle.com/error-help/db/ora-01439/
Fixrun as lab_a
ALTER TABLE emp ADD (hire_date DATE);
UPDATE emp SET hire_date = TO_DATE(TO_CHAR(hire_ymd), 'YYYYMMDD');
COMMIT;
ALTER TABLE emp DROP COLUMN hire_ymd;
OUTPUT
Table altered.


2 rows updated.


Commit complete.


Table altered.
After the fixrun as lab_a
SELECT emp_id, name, TO_CHAR(hire_date, 'YYYY-MM-DD') AS hire_date FROM emp ORDER BY emp_id;
✓ SUCCESS
    EMP_ID NAME                           HIRE_DATE
---------- ------------------------------ ----------
         1 KIM                            2024-03-01
         2 LEE                            2025-11-15

2 rows selected.

03Changing a NUMBER column to VARCHAR2 (e.g. zip codes)

Zip codes were in zip_code NUMBER, so the leading zero of 06236 was already lost (stored as 6236). MODIFY (zip_code VARCHAR2(5)) failed with ORA-01439.

This time the column was kept and emptied instead: copy the values to zip_backup, set zip_code = NULL, commit, and the same MODIFY succeeded. Then LPAD(TO_CHAR(zip_backup), 5, '0') filled it back, restoring 06236 and 48058, and zip_backup was dropped.

Setup
Setuprun as lab_a
CREATE TABLE customer (cust_id NUMBER, zip_code NUMBER);
INSERT INTO customer VALUES (1, 6236);
INSERT INTO customer VALUES (2, 48058);
COMMIT;
OUTPUT
Table created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
ALTER TABLE customer MODIFY (zip_code VARCHAR2(5));
✕ ERROR
ALTER TABLE customer MODIFY (zip_code VARCHAR2(5))
                             *
ERROR at line 1:
ORA-01439: column to be modified must be empty to change datatype
Help: https://docs.oracle.com/error-help/db/ora-01439/
Fixrun as lab_a
ALTER TABLE customer ADD (zip_backup NUMBER);
UPDATE customer SET zip_backup = zip_code, zip_code = NULL;
COMMIT;
ALTER TABLE customer MODIFY (zip_code VARCHAR2(5));
UPDATE customer SET zip_code = LPAD(TO_CHAR(zip_backup), 5, '0');
COMMIT;
ALTER TABLE customer DROP COLUMN zip_backup;
OUTPUT
Table altered.


2 rows updated.


Commit complete.


Table altered.


2 rows updated.


Commit complete.


Table altered.

This way the column keeps its name and no rename is needed. Do the backup copy and the NULL in one UPDATE and commit before the MODIFY.

After the fixrun as lab_a
SELECT cust_id, zip_code FROM customer ORDER BY cust_id;
✓ SUCCESS
   CUST_ID ZIP_C
---------- -----
         1 06236
         2 48058

2 rows selected.

FAQ

What does ORA-01439 column to be modified must be empty mean?

You can only change a column's data type when all its values are NULL. The column still has data, so Oracle refuses the MODIFY.

How do I change a column from VARCHAR2 to NUMBER when it has data?

Add a new NUMBER column, fill it with TO_NUMBER(old_column), drop the old column and rename the new one to the old name.

How do I convert a NUMBER yyyymmdd column to DATE?

Add a DATE column and run UPDATE ... SET new_col = TO_DATE(TO_CHAR(old_col), 'YYYYMMDD'), then drop the old column.

Can I avoid ORA-01439 without adding a new column?

Yes: copy the values somewhere, set the column to NULL, commit, run the MODIFY, then put the converted values back. The column keeps its name.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0