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 NULL) removes a NOT NULL constraint from a column. If the column is already nullable, or the NOT NULL rule comes from somewhere else (a CHECK constraint or a primary key), the statement fails with ORA-01451.
Below are three causes we reproduced on a real database, each with the fix we ran and its result.
01The column is already nullable
customers.phone was created without NOT NULL. ALTER TABLE customers MODIFY (phone NULL) failed with ORA-01451.
user_tab_columns showed NULLABLE = Y for PHONE, so there was nothing to change. For scripts that may run more than once, we checked nullable first and ran the MODIFY only when it was N. The block printed skip: PHONE is already nullable and finished without error.
Setup
CREATE TABLE customers (cust_id NUMBER PRIMARY KEY, phone VARCHAR2(20));Table created.ALTER TABLE customers MODIFY (phone NULL);ALTER TABLE customers MODIFY (phone NULL)
*
ERROR at line 1:
ORA-01451: column to be modified to NULL cannot be modified to NULL
Help: https://docs.oracle.com/error-help/db/ora-01451/COLUMN column_name FORMAT A12
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'CUSTOMERS' ORDER BY column_id;COLUMN_NAME N
------------ -
CUST_ID N
PHONE Y
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 = 'CUSTOMERS' AND column_name = 'PHONE';
IF v = 'N' THEN
EXECUTE IMMEDIATE 'ALTER TABLE customers MODIFY (phone NULL)';
DBMS_OUTPUT.PUT_LINE('modified');
ELSE
DBMS_OUTPUT.PUT_LINE('skip: PHONE is already nullable');
END IF;
END;
/skip: PHONE is already nullable
PL/SQL procedure successfully completed.02NOT NULL is enforced by a CHECK constraint, not the column definition
orders.memo had CONSTRAINT orders_memo_nn_ck CHECK (memo IS NOT NULL). To Oracle the column itself is nullable, so MODIFY (memo NULL) failed with ORA-01451.
user_constraints showed ORDERS_MEMO_NN_CK with type C and condition memo IS NOT NULL. After ALTER TABLE orders DROP CONSTRAINT orders_memo_nn_ck, inserting (2, NULL) succeeded.
Setup
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, memo VARCHAR2(100) CONSTRAINT orders_memo_nn_ck CHECK (memo IS NOT NULL));
INSERT INTO orders VALUES (1, 'first');
COMMIT;Table created.
1 row created.
Commit complete.ALTER TABLE orders MODIFY (memo NULL);ALTER TABLE orders MODIFY (memo NULL)
*
ERROR at line 1:
ORA-01451: column to be modified to NULL cannot be modified to NULL
Help: https://docs.oracle.com/error-help/db/ora-01451/COLUMN constraint_name FORMAT A18
COLUMN search_condition FORMAT A22
SELECT constraint_name, constraint_type, search_condition FROM user_constraints WHERE table_name = 'ORDERS' AND constraint_type = 'C';CONSTRAINT_NAME C SEARCH_CONDITION
------------------ - ----------------------
ORDERS_MEMO_NN_CK C memo IS NOT NULL
1 row selected.ALTER TABLE orders DROP CONSTRAINT orders_memo_nn_ck;Table altered.Look for type C constraints on the table. Drop the CHECK constraint instead of using MODIFY.
INSERT INTO orders VALUES (2, NULL);
COMMIT;
SELECT order_id, NVL(memo, '(null)') AS memo FROM orders ORDER BY order_id;1 row created.
Commit complete.
ORDER_ID MEMO
---------- ----------------------------------------------------------------------------------------------------
1 first
2 (null)
2 rows selected.03The column is part of the primary key
emp_skill had PRIMARY KEY (emp_id, skill_cd). MODIFY (skill_cd NULL) failed with ORA-01451. Both key columns showed NULLABLE = N.
Primary key columns cannot hold NULL. We dropped emp_skill_pk: both columns then showed NULLABLE = Y without any MODIFY. We added UNIQUE (emp_id, skill_cd) to keep duplicates out, and inserting (1, NULL) succeeded.
Setup
CREATE TABLE emp_skill (emp_id NUMBER, skill_cd VARCHAR2(10), CONSTRAINT emp_skill_pk PRIMARY KEY (emp_id, skill_cd));Table created.ALTER TABLE emp_skill MODIFY (skill_cd NULL);ALTER TABLE emp_skill MODIFY (skill_cd NULL)
*
ERROR at line 1:
ORA-01451: column to be modified to NULL cannot be modified to NULL
Help: https://docs.oracle.com/error-help/db/ora-01451/COLUMN column_name FORMAT A12
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'EMP_SKILL' ORDER BY column_id;COLUMN_NAME N
------------ -
EMP_ID N
SKILL_CD N
2 rows selected.COLUMN column_name FORMAT A12
ALTER TABLE emp_skill DROP CONSTRAINT emp_skill_pk;
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'EMP_SKILL' ORDER BY column_id;
ALTER TABLE emp_skill ADD CONSTRAINT emp_skill_uk UNIQUE (emp_id, skill_cd);Table altered.
COLUMN_NAME N
------------ -
EMP_ID Y
SKILL_CD Y
2 rows selected.
Table altered.Dropping the primary key also removes the NOT NULL it created, so no MODIFY is needed.
INSERT INTO emp_skill VALUES (1, NULL);
COMMIT;
COLUMN column_name FORMAT A12
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'EMP_SKILL' ORDER BY column_id;1 row created.
Commit complete.
COLUMN_NAME N
------------ -
EMP_ID Y
SKILL_CD Y
2 rows selected.FAQ
What does ORA-01451 mean?
You tried to make a column nullable with MODIFY (col NULL), but Oracle could not apply it: the column is already nullable, or it is part of a primary key.
How do I check if a column is nullable in Oracle?
Query user_tab_columns (or all_tab_columns): the NULLABLE column is Y for nullable and N for NOT NULL.
Why does a column still reject NULL after ORA-01451?
The rule may come from a CHECK constraint such as CHECK (col IS NOT NULL). Find it in user_constraints with type C and drop it.
Can a primary key column be made nullable?
Not while it is in the primary key. Drop the primary key first; the columns become nullable. A UNIQUE constraint can keep the values unique.
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