Which two queries execute successfully? (Choose two.)
Which two queries execute successfully? (Choose two.)
SELECT COALESCE(100, NULL, 200) FROM DUAL; executes successfully because COALESCE returns the first non-null value in its list of arguments, which in this case is 100. SELECT NULLIF(100, 100) FROM DUAL; also executes successfully because NULLIF returns NULL if both arguments are equal, which they are in this case. SELECT NULLIF(NULL, 100) FROM DUAL; causes an error because NULL cannot be compared directly. SELECT NULLIF(100, 'A') FROM DUAL; and SELECT COALESCE(100, 'A') FROM DUAL; cause errors because NULLIF and COALESCE require all arguments to be of the same data type, and mixing numbers and strings leads to data type inconsistency.
Tested both
D and E are correct SQL> SELECT COALESCE(100, NULL, 200) FROM DUAL; COALESCE(100,NULL,200) ---------------------- 100 SQL> SELECT NULLIF(100, 100) FROM DUAL; NULLIF(100,100) ---------------
D and E are correct.
D E is correct. Easy to test
D,E is correct A. ORA-00932: inconsistent datatypes: expected - got CHAR B. ORA-00932: inconsistent datatypes: expected NUMBER got CHAR C. ORA-00932: inconsistent datatypes: expected NUMBER got CHAR D. SQL> SELECT COALESCE(100, NULL, 200) FROM DUAL; COALESCE(100,NULL,200) ---------------------- 100 E. SQL> SELECT NULLIF(100, 100) FROM DUAL; NULLIF(100,100) ---------------
D, E confirmed
NULLIF must have the same data type, not use number and string in the same expression. COALESCE returns the first non-null value of the expression, but without using numbers and string.
D and E .Confirmed.