Chapter 5 Conditional Control: IF Statements
1) | Rewrite ch05_1a.sql. Instead of getting information from the user for the variable v_date, define its value with the help of the function SYSDATE. After it has been determined that a certain day falls on the weekend, check to see if the time is before or after noon. Display the time of the day together with the day. |
A1: |
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 ... |
Get Oracle® PL/SQL® Interactive Workbook, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.