Database Programming With PL/SQL 2-1: Practice Activities
Database Programming With PL/SQL 2-1: Practice Activities
Database Programming With PL/SQL 2-1: Practice Activities
com
Try It / Solve It
1. Fill in the blanks.
number_of_copies PLS_INTEGER;
printer_name CONSTANT VARCHAR2(10);
deliver_to VARCHAR2(10) := Johnson;
by_when DATE := SYSDATE+1;
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
2
3. Examine the following anonymous block and choose the appropriate statement.
DECLARE
fname VARCHAR2(25);
lname VARCHAR2(25) DEFAULT 'fernandez';
BEGIN
DBMS_OUTPUT.PUT_LINE(fname || ' ' || lname);
END;
E. The block will give an error because the FNAME variable is not declared.
4. In Application Express:
DECLARE
v_length_of_string INTEGER;
BEGIN
v_length_of_string := num_characters('Oracle Corporation');
DBMS_OUTPUT.PUT_LINE(v_length_of_string);
END;
5. Write an anonymous block that uses a country name as input and prints the highest and lowest
elevations for that country. Use the COUNTRIES table. Execute your block three times using Unit-
ed States of America, French Republic, and Japan.
DECLARE
v_country_name varchar2(50):= 'United States of America';
v_lowest_elevation number(6);
v_highest_elevation number(6);
BEGIN
SELECT lowest_elevation, highest_elevation
INTO v_lowest_elevation, v_highest_elevation
FROM wf_countries
WHERE country_name = v_country_name;
DBMS_OUTPUT.PUT_LINE('The lowest elevation for '||v_country_name ||' is:'||
v_lowest_elevation);
DBMS_OUTPUT.PUT_LINE('The highest elevation for '||v_country_name ||' is:'||
v_highest_elevation);
END;
DECLARE
v_country_name varchar2(50):= 'French Republic';
v_lowest_elevation number(6);
v_highest_elevation number(6);
BEGIN
SELECT lowest_elevation, highest_elevation
INTO v_lowest_elevation, v_highest_elevation
FROM wf_countries
WHERE country_name = v_country_name;
DBMS_OUTPUT.PUT_LINE('The lowest elevation for '||v_country_name ||' is:'||
v_lowest_elevation);
DBMS_OUTPUT.PUT_LINE('The highest elevation for '||v_country_name ||' is:'||
v_highest_elevation);
END;
DECLARE
v_country_name varchar2(50):= 'Japan';
v_lowest_elevation number(6);
v_highest_elevation number(6);
BEGIN
SELECT lowest_elevation, highest_elevation
INTO v_lowest_elevation, v_highest_elevation
FROM wf_countries
WHERE country_name = v_country_name;
DBMS_OUTPUT.PUT_LINE('The lowest elevation for '||v_country_name ||' is:'||
v_lowest_elevation);
DBMS_OUTPUT.PUT_LINE('The highest elevation for '||v_country_name ||' is:'||
v_highest_elevation);
END;