Lab 2.2 Exercises


2.2.1 Use Substitution Variables

In this exercise, you will calculate the square of a number. The value of the number will be provided with the help of a substitution variable. Then the result will be displayed on the screen.

Create the following PL/SQL script:

 
 -- ch02_1a.sql, version 1.0 SET SERVEROUTPUT ON DECLARE    v_num NUMBER := &sv_num;    v_result NUMBER; BEGIN    v_result := POWER(v_num, 2);    DBMS_OUTPUT.PUT_LINE ('The value of v_result is: '       v_result); END; 

Execute the script, and then answer the following questions:

a)

If the value of v_num is equal to 10, what output is printed on the screen?

b)

What is the purpose of using a substitution variable?

c)

Why is it considered a good practice to enclose substitution variables with single quotes for string datatypes?


2.2.2 Use the DBMS_OUTPUT.PUT_LINE Statement

In this exercise, you will determine the day of the week based on today's date. You will then display the results on the screen.

Create the following PL/SQL script:

 
 -- ch02_2a.sql, version 1.0 SET SERVEROUTPUT ON DECLARE    v_day VARCHAR2(20); BEGIN    v_day := TO_CHAR(SYSDATE, 'Day');    DBMS_OUTPUT.PUT_LINE ('Today is 'v_day); END; 

Execute the script, and then answer the following questions:

a)

What was printed on the screen?

b)

What will be printed on the screen if the statement SET SERVEROUTPUT OFF is issued? Why?

c)

How would you change the script to display the time of the day as well?




Oracle PL[s]SQL by Example
Oracle PL[s]SQL by Example
ISBN: 3642256902
EAN: N/A
Year: 2003
Pages: 289

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