Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-26 · container image gvenzl/oracle-free:23-slim
ALTER TABLE ... MODIFY (col NOT NULL) adds a NOT NULL constraint. If the column already has one, Oracle stops with ORA-01442 instead of ignoring it.
Below are three ways this happens in practice, reproduced on a real database, with the fix we ran and its result.
01The column is already NOT NULL
products.name was created as NOT NULL. ALTER TABLE products MODIFY (name NOT NULL) failed with ORA-01442.
user_tab_columns showed NULLABLE = N for NAME. For scripts that may run more than once, we checked nullable first and ran the MODIFY only when it was Y. The block printed skip: NAME is already NOT NULL and finished without error.
Setup
CREATE TABLE products (product_id NUMBER PRIMARY KEY, name VARCHAR2(50) NOT NULL);Table created.ALTER TABLE products MODIFY (name NOT NULL);ALTER TABLE products MODIFY (name NOT NULL)
*
ERROR at line 1:
ORA-01442: column to be modified to NOT NULL is already NOT NULL
Help: https://docs.oracle.com/error-help/db/ora-01442/COLUMN column_name FORMAT A12
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'PRODUCTS' ORDER BY column_id;COLUMN_NAME N
------------ -
PRODUCT_ID N
NAME N
2 rows selected.Use the check-first block in migration scripts that can run twice.
SET SERVEROUTPUT ON
DECLARE
v VARCHAR2(1);
BEGIN
SELECT nullable INTO v FROM user_tab_columns WHERE table_name = 'PRODUCTS' AND column_name = 'NAME';
IF v = 'Y' THEN
EXECUTE IMMEDIATE 'ALTER TABLE products MODIFY (name NOT NULL)';
DBMS_OUTPUT.PUT_LINE('modified');
ELSE
DBMS_OUTPUT.PUT_LINE('skip: NAME is already NOT NULL');
END IF;
END;
/skip: NAME is already NOT NULL
PL/SQL procedure successfully completed.02A CREATE TABLE AS SELECT copy kept the NOT NULL
emp_bak was made with CREATE TABLE emp_bak AS SELECT * FROM emp. name was NOT NULL in emp, and ALTER TABLE emp_bak MODIFY (name NOT NULL) failed with ORA-01442.
user_tab_columns for EMP_BAK showed NAME = N, but EMP_ID = Y: the explicit NOT NULL on name was copied, the one created by the primary key on emp_id was not. MODIFY (emp_id NOT NULL) succeeded.
Setup
CREATE TABLE emp (emp_id NUMBER PRIMARY KEY, name VARCHAR2(30) NOT NULL, dept_id NUMBER);
INSERT INTO emp VALUES (1, 'KIM', 10);
COMMIT;
CREATE TABLE emp_bak AS SELECT * FROM emp;Table created.
1 row created.
Commit complete.
Table created.ALTER TABLE emp_bak MODIFY (name NOT NULL);ALTER TABLE emp_bak MODIFY (name NOT NULL)
*
ERROR at line 1:
ORA-01442: column to be modified to NOT NULL is already NOT NULL
Help: https://docs.oracle.com/error-help/db/ora-01442/COLUMN column_name FORMAT A12
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'EMP_BAK' ORDER BY column_id;COLUMN_NAME N
------------ -
EMP_ID Y
NAME N
DEPT_ID Y
3 rows selected.After CTAS, check user_tab_columns and add NOT NULL only to the columns showing Y.
ALTER TABLE emp_bak MODIFY (emp_id NOT NULL);Table altered.03One already-NOT NULL column in a multi-column MODIFY
ALTER TABLE members MODIFY (email NOT NULL, nickname NOT NULL) failed with ORA-01442 because email was already NOT NULL.
The whole statement was rejected: right after the error, NICKNAME was still NULLABLE = Y. Running MODIFY (nickname NOT NULL) alone succeeded, and all three columns then showed N.
Setup
CREATE TABLE members (member_id NUMBER PRIMARY KEY, email VARCHAR2(50) NOT NULL, nickname VARCHAR2(30));
INSERT INTO members VALUES (1, 'kim@example.com', 'kim');
COMMIT;Table created.
1 row created.
Commit complete.ALTER TABLE members MODIFY (email NOT NULL, nickname NOT NULL);
COLUMN column_name FORMAT A12
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'MEMBERS' ORDER BY column_id;ALTER TABLE members MODIFY (email NOT NULL, nickname NOT NULL)
*
ERROR at line 1:
ORA-01442: column to be modified to NOT NULL is already NOT NULL
Help: https://docs.oracle.com/error-help/db/ora-01442/
COLUMN_NAME N
------------ -
MEMBER_ID N
EMAIL N
NICKNAME Y
3 rows selected.ALTER TABLE members MODIFY (nickname NOT NULL);Table altered.One column already NOT NULL cancels the whole MODIFY. Leave it out and list only the columns that need it.
COLUMN column_name FORMAT A12
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'MEMBERS' ORDER BY column_id;COLUMN_NAME N
------------ -
MEMBER_ID N
EMAIL N
NICKNAME N
3 rows selected.FAQ
What does ORA-01442 mean?
You ran MODIFY (col NOT NULL) on a column that already has a NOT NULL constraint. Nothing needs to change.
How do I add NOT NULL only if it doesn't exist?
Read nullable from user_tab_columns in a PL/SQL block and run the ALTER TABLE with EXECUTE IMMEDIATE only when it is Y.
Does CREATE TABLE AS SELECT copy NOT NULL constraints?
In our test, the explicit NOT NULL was copied but the NOT NULL that came from the primary key was not. Check user_tab_columns on the copy.
Were the other columns changed when ORA-01442 occurred?
No. In a multi-column MODIFY, the whole statement fails; the other columns stay nullable.
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