Multiple choice

Which of the following SELECT statements should be used to extract the year from the system date to display it in the format “2001”?

  1. SELECT TO_CHAR(SYSDATE, 'yyyy') FROM dual;

  2. SELECT TO_DATE(SYSDATE, 'yyyy') FROM dual;

  3. SELECT DECODE(SUBSTR(SYSDATE, 8), 'YYYY') FROM dual;

  4. SELECT DECODE(SUBSTR(SYSDATE, 8), 'year') FROM dual;

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

TO_CHAR converts a date value to a string with the specified format mask. The 'yyyy' format element extracts the 4-digit year from SYSDATE. TO_DATE is incorrect because it converts a string to a date, not the reverse. DECODE is not relevant for date formatting.