Question 1
A report must render the clock time five minutes past eight in the evening as the character string `08:05 PM`. Which query returns exactly that string?
A. SELECT TO_CHAR(TO_DATE('20:05', 'HH24:MI'), 'HH24:MI AM') FROM dual
Assumes the AM meridian element makes the hour render in 12-hour form. The meridian indicator only appends AM or PM; HH24 still formats the hour as 0-23, so this produces '20:05 PM'.
B. SELECT TO_CHAR(TO_DATE('20:05', 'HH:MI'), 'HH:MI AM') FROM dual
Assumes HH in a conversion format model accepts a 24-hour value. HH means HH12 and constrains the hour to 1-12, so parsing '20' raises ORA-01849: hour must be between 1 and 12 and the query returns nothing.
C. SELECT TO_CHAR(TO_DATE('08:05', 'HH24:MI'), 'HH:MI AM') FROM dual
Assumes the meridian element in the output model can assign the afternoon half of the day. The meridian is derived from the stored hour, and HH24 read '08' as 8 in the morning, so this produces '08:05 AM'.
D. SELECT TO_CHAR(TO_DATE('20:05', 'HH24:MI'), 'HH:MI AM') FROM dualCorrect answer
Correct. HH24 on input accepts the hour 20, and on output HH (a synonym for HH12) renders it as 08 while the AM element supplies the correct meridian indicator PM, giving '08:05 PM'.
Explanation
Hour format elements are directional in effect but identical in meaning on both sides of a conversion: HH and HH12 cover 1-12 and HH24 covers 0-23. A 24-hour source string must therefore be parsed with HH24, or the value is rejected as out of range, while the character output must use HH or HH12 for a two-digit 12-hour clock. The AM/PM meridian element never rescales the hour — it merely reports which half of the day the stored time falls in — so pairing it with HH24 leaves the hour unchanged.