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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.