Oracle Database SQL (1Z0-071) Practice Questions

Oracle Database SQL (1Z0-071) exam preparation

Oracle Database SQL (1Z0-071) practice questions in English: 180 questions with explanations. The mock exam has 78 questions and 120 minutes.

Oracle Database SQL (1Z0-071) free question 7 / 10 · Domain 5: Using Conversion Functions and Conditional Expressions

Which is the result of the following SELECT statement? SELECT NULLIF(80, 100), NULLIF(100, 100) FROM dual;

  1. 100 and NULL: the second argument when the values differ, NULL when they are equal
  2. 80 and NULL: the first argument when the values differ, NULL when they are equal
  3. NULL and 100: NULL when the values differ, the second argument when they are equal
  4. NULL and NULL: both pairs are judged to be equal
Show the answer and explanation

Answer: B

Why this is correct
NULLIF in the SQL Language Reference compares expr1 and expr2, and if they are equal the function returns null; otherwise it returns expr1. 80 and 100 are different, so the result is 80, and 100 and 100 are equal, so the result is NULL.

Why the other options are wrong
"NULL and NULL: both pairs are judged to be equal" … The pair 80 and 100 is not equal, so the first call does not return NULL; it returns the first argument, 80.
"100 and NULL: the second argument when the values differ, NULL when they are equal" … When the two expressions differ, NULLIF returns the first argument, not the second.
"NULL and 100: NULL when the values differ, the second argument when they are equal" … This is backwards. NULLIF returns NULL when the values are equal and the first argument when they are not.

Key takeaway
NULLIF(a, b) behaves like CASE WHEN a = b THEN NULL ELSE a END. You cannot specify the literal NULL as the first argument. Trace the example: NULLIF(80, 100) compares 80 with 100, finds them different, and returns the first argument, 80. NULLIF(100, 100) compares two equal values and returns NULL. Because the result can be NULL, NULLIF is often combined with functions that handle NULL, such as NVL or COALESCE.

Go to the Oracle Database SQL (1Z0-071) practice app (10 free questions; purchase unlocks all questions)

See the full practice set