O'Reilly logo

Oracle® PL/SQL® Interactive Workbook, Second Edition by Elena Silvestrova, Benjamin Rosenzweig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required