Examine the structure of the PROGRAMS table:
name Null Type
PROG_ID NOT NULL NUMBER(3)
PROG_COST NUMBER(8,2)
START_DATE NOT NULL DATE
END_DATE DATE
Which two SQL statements would execute successfully? (Choose two.)
A.
SELECT NVL(ADD_MONTHS(END_DATE,1),SYSDATE)
FROM programs;
B.
SELECT TO_DATE(NVL(SYSDATE-END_DATE,SYSDATE))
FROM programs;
C.
SELECT NVL(MONTHS_BETWEEN(start_date,end_date),’Ongoing’)
FROM programs;
D.
SELECT NVL(TO_CHAR(MONTHS_BETWEEN(start_date,end_date)),’Ongoing’) FROM programs;
Can anybody explain why these two seem different answers are both correct? Thanks.
The guideline for NVL is same kind of datatype.
A is date datatype. (correct)
B. To-date is wrong, because nvl subquery result is already a date. Don’t convert a date to date datatype.
C has date date type and ‘Ongoing’ is character datatype. (wrong)
D. To_char converted the date datatype to character and ‘Ongoing’ is also character datatype
B. Number data type and string
C. Number data type and string
NOTE :it is required that all the arguments in the NVL function should be of same data type.
B is incorrect,but not for different data type of nvl.
It’s wrong because to_date() you can’t convert “SYSDATE-END_DATE” to a date type.