Examine the structure of the PROMOS table:
You want to display the list of promo names with the message ‘Same Day’ for promos that started
and ended on the same day.
Which query gives the correct output?
A.
SELECT promo_name, NVL(NULLIF(promo_start_date, promo_end_date), ‘Same Day’) FROM promos;
B.
SELECT promo_name, NVL(TRUNC(promo_end_date – promo_start_date), ‘Same Day’) FROM promos;
C.
SELECT promo_name, NVL2(TO_CHAR(TRUNC(promo_end_date-promo_start_date)), NULL,’Same Day’)
FROM promos;
D.
SELECT promo_name, DECODE((NULLIF(promo_start_date, promo_end_date)), NULL,’Same day’) FROM
promos;
Explanation:
The NULLIF Function
The NULLIF function tests two terms for equality. If they are equal the function returns a null, else
it returns the first of the two terms tested.
The NULLIF function takes two mandatory parameters of any data type. The syntax is
NULLIF(ifunequal, comparison_term), where the parameters ifunequal and comparison_term are
compared. If they are identical, then NULL is returned. If they differ, the ifunequal parameter is
returned ANSWER A – date and String incompatibl;a datatypes for NVL function The Date TRUNC
Function
The date TRUNC function performs a truncation operation on a date value based on a specified
date precision format.
The date TRUNC function takes one mandatory and one optional parameter.
Its syntax is TRUNC(source date, [date precision format]). The source date parameter represents
any value that can be implicitly converted into a date item. The date precision format parameter
specifies the degree of truncation and is optional. If it is absent, the default degree of truncation is
day. This means that any time component