Oracle 23.26ConstraintsLab-verified · 2026-11-19

ORA-01407: cannot update (column) to NULL

An UPDATE tried to set a NOT NULL column to NULL.

Oracle AI Database 26ai Free 23.26.3.0.0
ORA-01407: cannot update ("LAB_A"."EMPLOYEES"."DEPT_CODE") to NULL

Jump to a cause

  1. 01A correlated subquery UPDATE finds no match for some rows
  2. 02Setting the column to an empty string ''
  3. 03SET col = NULL on a column defined as NOT NULL

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

ORA-01407 is the UPDATE version of ORA-01400. The message names the column as ("LAB_A"."EMPLOYEES"."DEPT_CODE"): schema, table, column. That column is NOT NULL and the new value was NULL.

Often nobody wrote NULL on purpose. A subquery that returns no row, or an empty string '', also becomes NULL. The whole statement fails, so no row is changed.

01A correlated subquery UPDATE finds no match for some rows

SET dept_code = (SELECT m.new_code FROM dept_map m WHERE m.old_code = e.dept_code) updates every row of employees. Employee 3 has D99, which is not in dept_map. For that row the subquery returns nothing, so the new value is NULL.

The LEFT JOIN check shows it: NEW_CODE is empty for employee 3. Adding WHERE EXISTS (...) with the same condition limits the UPDATE to rows that have a match. Result: 2 rows updated, employees 1 and 2 got S10 and S20, and employee 3 kept D99.

Setup
Setuprun as lab_a
CREATE TABLE employees (emp_id NUMBER PRIMARY KEY, emp_name VARCHAR2(30) NOT NULL, dept_code VARCHAR2(10) NOT NULL);
CREATE TABLE dept_map (old_code VARCHAR2(10), new_code VARCHAR2(10));
INSERT INTO employees VALUES (1, 'Kim', 'D10');
INSERT INTO employees VALUES (2, 'Lee', 'D20');
INSERT INTO employees VALUES (3, 'Park', 'D99');
INSERT INTO dept_map VALUES ('D10', 'S10');
INSERT INTO dept_map VALUES ('D20', 'S20');
COMMIT;
OUTPUT
Table created.


Table created.


1 row created.


1 row created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
UPDATE employees e
   SET dept_code = (SELECT m.new_code FROM dept_map m WHERE m.old_code = e.dept_code);
✕ ERROR
   SET dept_code = (SELECT m.new_code FROM dept_map m WHERE m.old_code = e.dept_code)
       *
ERROR at line 2:
ORA-01407: cannot update ("LAB_A"."EMPLOYEES"."DEPT_CODE") to NULL
Help: https://docs.oracle.com/error-help/db/ora-01407/
Checkrun as lab_a
SELECT e.emp_id, e.dept_code, m.new_code
  FROM employees e LEFT JOIN dept_map m ON m.old_code = e.dept_code
 ORDER BY e.emp_id;
OUTPUT
    EMP_ID DEPT_CODE  NEW_CODE
---------- ---------- ----------
         1 D10        S10
         2 D20        S20
         3 D99

3 rows selected.

Whenever you use SET col = (SELECT ...), add a WHERE EXISTS with the same condition, or the rows without a match are set to NULL.

After the fixrun as lab_a
UPDATE employees e
   SET dept_code = (SELECT m.new_code FROM dept_map m WHERE m.old_code = e.dept_code)
 WHERE EXISTS (SELECT 1 FROM dept_map m WHERE m.old_code = e.dept_code);
SELECT emp_id, dept_code FROM employees ORDER BY emp_id;
✓ SUCCESS
2 rows updated.


    EMP_ID DEPT_CODE
---------- ----------
         1 S10
         2 S20
         3 D99

3 rows selected.

02Setting the column to an empty string ''

UPDATE employees SET emp_name = '' looks like it stores an empty string, but in Oracle '' is NULL in VARCHAR2. The check CASE WHEN '' IS NULL ... returns NULL.

So a NOT NULL text column cannot be "blank". Here a placeholder value '-' was stored instead and the UPDATE succeeded.

Setup
Setuprun as lab_a
CREATE TABLE employees (emp_id NUMBER PRIMARY KEY, emp_name VARCHAR2(30) NOT NULL, dept_code VARCHAR2(10) NOT NULL);
CREATE TABLE dept_map (old_code VARCHAR2(10), new_code VARCHAR2(10));
INSERT INTO employees VALUES (1, 'Kim', 'D10');
INSERT INTO employees VALUES (2, 'Lee', 'D20');
INSERT INTO employees VALUES (3, 'Park', 'D99');
INSERT INTO dept_map VALUES ('D10', 'S10');
INSERT INTO dept_map VALUES ('D20', 'S20');
COMMIT;
OUTPUT
Table created.


Table created.


1 row created.


1 row created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
UPDATE employees SET emp_name = '' WHERE emp_id = 3;
✕ ERROR
UPDATE employees SET emp_name = '' WHERE emp_id = 3
                     *
ERROR at line 1:
ORA-01407: cannot update ("LAB_A"."EMPLOYEES"."EMP_NAME") to NULL
Help: https://docs.oracle.com/error-help/db/ora-01407/
Checkrun as lab_a
SELECT CASE WHEN '' IS NULL THEN 'NULL' ELSE 'NOT NULL' END AS empty_string FROM dual;
OUTPUT
EMPTY_ST
--------
NULL

1 row selected.

Code moved from MySQL or SQL Server often relies on '' being different from NULL. Decide on a real placeholder value, or allow NULL.

After the fixrun as lab_a
UPDATE employees SET emp_name = '-' WHERE emp_id = 3;
SELECT emp_id, emp_name FROM employees ORDER BY emp_id;
✓ SUCCESS
1 row updated.


    EMP_ID EMP_NAME
---------- ------------------------------
         1 Kim
         2 Lee
         3 -

3 rows selected.

03SET col = NULL on a column defined as NOT NULL

UPDATE employees SET dept_code = NULL fails because USER_TAB_COLUMNS shows NULLABLE = N for DEPT_CODE.

If the business rule really allows an empty department, change the column with ALTER TABLE employees MODIFY (dept_code NULL). After that the same UPDATE ran and employee 3's DEPT_CODE is empty.

Setup
Setuprun as lab_a
CREATE TABLE employees (emp_id NUMBER PRIMARY KEY, emp_name VARCHAR2(30) NOT NULL, dept_code VARCHAR2(10) NOT NULL);
CREATE TABLE dept_map (old_code VARCHAR2(10), new_code VARCHAR2(10));
INSERT INTO employees VALUES (1, 'Kim', 'D10');
INSERT INTO employees VALUES (2, 'Lee', 'D20');
INSERT INTO employees VALUES (3, 'Park', 'D99');
INSERT INTO dept_map VALUES ('D10', 'S10');
INSERT INTO dept_map VALUES ('D20', 'S20');
COMMIT;
OUTPUT
Table created.


Table created.


1 row created.


1 row created.


1 row created.


1 row created.


1 row created.


Commit complete.
Reproducerun as lab_a
UPDATE employees SET dept_code = NULL WHERE emp_id = 3;
✕ ERROR
UPDATE employees SET dept_code = NULL WHERE emp_id = 3
                     *
ERROR at line 1:
ORA-01407: cannot update ("LAB_A"."EMPLOYEES"."DEPT_CODE") to NULL
Help: https://docs.oracle.com/error-help/db/ora-01407/
Checkrun as lab_a
SELECT column_name, nullable FROM user_tab_columns WHERE table_name = 'EMPLOYEES' ORDER BY column_id;
OUTPUT
COLUMN_NAME                    N
------------------------------ -
EMP_ID                         N
EMP_NAME                       N
DEPT_CODE                      N

3 rows selected.

Remove NOT NULL only when the rule has really changed. If not, the UPDATE needs a real value.

After the fixrun as lab_a
ALTER TABLE employees MODIFY (dept_code NULL);
UPDATE employees SET dept_code = NULL WHERE emp_id = 3;
SELECT emp_id, dept_code FROM employees ORDER BY emp_id;
✓ SUCCESS
Table altered.


1 row updated.


    EMP_ID DEPT_CODE
---------- ----------
         1 D10
         2 D20
         3

3 rows selected.

FAQ

How do I find which column causes ORA-01407?

The message shows it as ("SCHEMA"."TABLE"."COLUMN"). The last part is the column.

My UPDATE with a subquery fails with ORA-01407 but the subquery has no NULLs. Why?

Some rows have no matching row in the subquery, so the subquery returns nothing and the value becomes NULL. Add WHERE EXISTS with the same condition so only matching rows are updated.

Why does setting a column to '' give ORA-01407?

In Oracle, an empty string '' is treated as NULL. A NOT NULL VARCHAR2 column cannot hold it.

What is the difference between ORA-01407 and ORA-01400?

ORA-01400 comes from INSERT, ORA-01407 from UPDATE. Both mean a NOT NULL column would get NULL.

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