ORA-01402: view WITH CHECK OPTION where-clause violation
ORA-01402 is raised when you attempt to INSERT or UPDATE data through an Oracle view that was created with the WITH CHECK OPTION clause, and the resulting row would not be visible through that view's WHERE condition. Essentially, Oracle prevents you from making a change that would cause the affected row to "disappear" from the view after the DML operation. This is a deliberate data integrity mechanism, not a bug.
Top 3 Causes
1. Inserting Data That Violates the View's WHERE Condition
The most common cause. When a view filters rows by a specific condition (e.g., deptno = 10), inserting a row that doesn't satisfy that condition triggers ORA-01402.
-- Create a base table
CREATE TABLE emp (
empno NUMBER,
ename VARCHAR2(20),
deptno NUMBER,
sal NUMBER
);
INSERT INTO emp VALUES (101, 'SMITH', 10, 3000);
COMMIT;
-- Create view with WITH CHECK OPTION
CREATE OR REPLACE VIEW v_emp_dept10 AS
SELECT empno, ename, deptno, sal
FROM emp
WHERE deptno = 10
WITH CHECK OPTION;
-- This will raise ORA-01402 because deptno = 20 violates the view's WHERE clause
INSERT INTO v_emp_dept10 (empno, ename, deptno, sal)
VALUES (102, 'JONES', 20, 2500);
-- Correct: insert data that satisfies the WHERE condition
INSERT INTO v_emp_dept10 (empno, ename, deptno, sal)
VALUES (103, 'ADAMS', 10, 2800);
COMMIT;
2. Updating a Column Referenced in the View's WHERE Clause
If you try to update a column that is part of the view's WHERE condition to a value outside the allowed range, ORA-01402 is raised because the row would no longer be accessible via the view.
-- This raises ORA-01402: changing deptno from 10 to 30 violates the view filter
UPDATE v_emp_dept10
SET deptno = 30
WHERE empno = 101;
-- Fix 1: Only update columns NOT part of the WHERE condition
UPDATE v_emp_dept10
SET sal = 3500
WHERE empno = 101;
COMMIT;
-- Fix 2: Update the base table directly if department change is required
UPDATE emp
SET deptno = 30
WHERE empno = 101;
COMMIT;
3. Cascaded CHECK OPTION Violation in Nested Views
When a view is built on top of another view using WITH CASCADED CHECK OPTION, ALL WHERE conditions across all view layers must be satisfied simultaneously. Missing any one condition causes ORA-01402.
-- Parent view: only dept 10 and 20
CREATE OR REPLACE VIEW v_parent AS
SELECT empno, ename, deptno, sal
FROM emp
WHERE deptno IN (10, 20)
WITH CHECK OPTION;
-- Child view: only high earners, cascaded check
CREATE OR REPLACE VIEW v_child AS
SELECT empno, ename, deptno, sal
FROM v_parent
WHERE sal >= 3000
WITH CASCADED CHECK OPTION;
-- ORA-01402: deptno 30 violates parent view condition
INSERT INTO v_child (empno, ename, deptno, sal)
VALUES (104, 'MILLER', 30, 4000);
-- ORA-01402: sal 1500 violates child view condition
INSERT INTO v_child (empno, ename, deptno, sal)
VALUES (105, 'FORD', 10, 1500);
-- Correct: satisfies ALL conditions across all view layers
INSERT INTO v_child (empno, ename, deptno, sal)
VALUES (106, 'KING', 10, 4500);
COMMIT;
Quick Fix Solutions
- Check the view definition before running DML to understand what conditions must be met:
-- Inspect the view's DDL
SELECT text FROM user_views WHERE view_name = 'V_EMP_DEPT10';
-- Check WITH CHECK OPTION constraints
SELECT constraint_name, constraint_type, view_name
FROM user_constraints
WHERE constraint_type = 'V';
- Bypass the view and insert/update the base table directly when business logic requires data outside the view's scope.
-
Remove
WITH CHECK OPTIONfrom the view if the restriction is no longer needed — but do this only after confirming it won't compromise data security.
Prevention Tips
Document all views with
WITH CHECK OPTIONin your DB design specs and communicate the DML constraints clearly to developers. Consider wrapping DML against such views inside stored procedures that validate input before execution.Include view constraint checks in your pre-deployment testing. Before releasing any code that performs DML through a view, verify that all inserted/updated values satisfy the view's WHERE conditions. Use
user_constraintswithconstraint_type = 'V'as part of your DB review checklist.
Related Errors
- ORA-01779 — Cannot modify a column mapped to a non key-preserved table in a join view.
- ORA-01732 — DML not permitted on views containing GROUP BY, DISTINCT, or aggregate functions.
- ORA-01733 — Attempt to assign a value to a virtual (expression-based) column in a view.
📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.
Top comments (0)