Answer: Your answer should look similar to the following. All changes are shown in bold letters. SET SERVEROUTPUT ON DECLARE v_day VARCHAR2(15); v_time VARCHAR(8); BEGIN v_day := TO_CHAR(SYSDATE, 'fmDAY'); v_time := TO_CHAR(SYSDATE, 'HH24:MI'); IF v_day IN ('SATURDAY', 'SUNDAY') THEN DBMS_OUTPUT.PUT_LINE (v_day||', '||v_time); IF v_time BETWEEN '12:01' AND '24:00' THEN DBMS_OUTPUT.PUT_LINE ('It''s afternoon'); ELSE DBMS_OUTPUT.PUT_LINE ('It''s morning'); END IF; END IF; -- control resumes here DBMS_OUTPUT.PUT_LINE('Done…'); END; In this exercise, you remove variable v_date that was used to store date provided by a user. Instead, you add variable v_time to store the time of the day. You also modify the statement v_day := TO_CHAR(SYSDATE, 'fmDAY'); so that 'DAY' is prefixed by letters 'fm'. This guarantees that extra spaces will be removed from the name of the day. Then you add another statement that determines current time of the day and stores it in the variable v_time. Finally, you add an IF-THEN-ELSE statement that checks the time of the day and displays the appropriate message. Notice that two single quotes are used in the second and third DBMS_OUTPUT. PUT_LINE statements. This allows you to use an apostrophe in your message. When run, this exercise produces the following output: SUNDAY, 16:19 It's afternoon Done… PLSQL procedure successfully completed. |