Chapter 5 Test Your Thinking

Team-Fly    

Oracle® PL/SQL® Interactive Workbook, Second Edition
By Benjamin Rosenzweig, Elena Silvestrova
Table of Contents
Chapter 5.  Conditional Control: IF Statements


In this chapter you learned about different types of IF statements. You also learned that all of these different IF statements can be nested one inside another. Here are some exercises that will help you test the depth of your understanding.

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.

2)

Create a new script. For a given instructor, determine how many sections he or she is teaching. If the number is greater than or equal to 3, display a message saying that the instructor needs a vacation. Otherwise, display a message saying how many sections this instructor is teaching.

3)

Execute the two PL/SQL blocks below and explain why they produce different output for the same value of the variable v_num. Remember to issue the SET SERVEROUTPUT ON command before running this script.

 -- Block 1  DECLARE     v_num NUMBER := NULL;  BEGIN     IF v_num > 0 THEN        DBMS_OUTPUT.PUT_LINE ('v_num is greater than 0');     ELSE        DBMS_OUTPUT.PUT_LINE           ('v_num is not greater than 0');     END IF;  END;  -- Block 2  DECLARE     v_num NUMBER := NULL;  BEGIN     IF v_num > 0 THEN        DBMS_OUTPUT.PUT_LINE ('v_num is greater than 0');     END IF;     IF NOT (v_num > 0) THEN        DBMS_OUTPUT.PUT_LINE           ('v_num is not greater than 0');     END IF;  END; 

The projects in this section are meant to have you utilize all of the skills that you have acquired throughout this chapter. The answers to these projects can be found in Appendix D and at the companion Web site to this book, located at http://www.phptr.com/rosenzweig2e. Visit the Web site periodically to share and discuss your answers.


    Team-Fly    
    Top
     



    Oracle PL. SQL Interactive Workbook
    Oracle PL/SQL Interactive Workbook (2nd Edition)
    ISBN: 0130473200
    EAN: 2147483647
    Year: 2002
    Pages: 146

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net