Question 1
You are preparing to add a CHECK constraint to the EMPLOYEES table: ``` ALTER TABLE employees ADD CONSTRAINT emp_comm_ck CHECK (commission BETWEEN 0.10 AND 0.20); ``` COMMISSION is a nullable NUMBER(4,2) column and some rows currently hold NULL. Adding the constraint validates every existing row, and the statement fails with ORA-02293 if any existing row would violate it. Before running the ALTER TABLE, you want a report of exactly which existing rows would make it fail. Which query returns the EMP_ID of every row — and only those rows — that would cause the ALTER TABLE to fail?
A. SELECT emp_id FROM employees WHERE commission NOT BETWEEN 0.10 AND 0.20 ORDER BY emp_idCorrect answer
NOT BETWEEN is TRUE only for a non-NULL commission outside the inclusive range 0.10..0.20 — exactly the rows for which the CHECK condition evaluates to FALSE. Rows with a NULL commission yield UNKNOWN for both the constraint and this predicate, so they are correctly left out.
B. SELECT emp_id FROM employees WHERE commission NOT BETWEEN 0.10 AND 0.20 OR commission IS NULL ORDER BY emp_id
Treats an UNKNOWN condition as a violation. A CHECK constraint rejects a row only when its condition evaluates to FALSE; with a NULL commission the condition is UNKNOWN, which satisfies the constraint, so these NULL rows are reported as offenders when they are not.
C. SELECT emp_id FROM employees WHERE commission <= 0.10 OR commission >= 0.20 ORDER BY emp_id
Reads BETWEEN as exclusive. BETWEEN 0.10 AND 0.20 expands to 0.10 <= commission AND commission <= 0.20, so the endpoint values 0.10 and 0.20 satisfy the constraint; this query wrongly flags rows sitting exactly on the boundaries.
D. SELECT emp_id FROM employees WHERE commission IS NULL ORDER BY emp_id
Confuses CHECK with NOT NULL. A CHECK constraint does not reject NULLs unless its condition explicitly says so (for example, IS NOT NULL); NULL commissions pass this constraint, while genuinely out-of-range values are missed entirely.
Explanation
When a CHECK constraint is added, Oracle validates existing rows and rejects only those for which the condition evaluates to FALSE — a condition that evaluates to UNKNOWN because of a NULL is treated as satisfied. BETWEEN is inclusive of both endpoints, expanding to lower <= expr AND expr <= upper, so boundary values comply. The pre-check query must therefore select non-NULL values outside the inclusive range and nothing else.