Sei sulla pagina 1di 5

L4S1-6

Ans:
DECLARE
v_cnp wf_countries.population%TYPE ;
v_cname wf_countries.COUNTRY_NAME%TYPE;

BEGIN
SELECT population,COUNTRY_NAME
WHERE country_id=86;

INTO

v_cnp,v_cname

FROM

wf_countries

IF v_cnp>1000000000 THEN
DBMS_OUTPUT.PUT_LINE('Population is greater than 1 billion :- ' ||v_cnp);
END IF;

SELECT population,COUNTRY_NAME
WHERE country_id=44;

INTO

v_cnp,v_cname

FROM

wf_countries

IF v_cnp> 0 THEN
DBMS_OUTPUT.PUT_LINE(' Population is greater than 0 :- ' ||v_cnp);
END IF;

SELECT population,COUNTRY_NAME
WHERE country_id=672;

INTO

v_cnp,v_cname

FROM

wf_countries

FROM

wf_countries

IF v_cnp < 1 AND v_cnp >-1 THEN


DBMS_OUTPUT.PUT_LINE(' Population is 0 :- ' ||v_cnp);
END IF;

SELECT population,COUNTRY_NAME
WHERE country_id=15;

INTO

v_cnp,v_cname

IF v_cnp IS NULL THEN


DBMS_OUTPUT.PUT_LINE(' There is no data for this country');
END IF;

END;

Result :
Population is greater than 1 billion :- 1313973713
Population is greater than 0 :- 60609153
Population is 0 :- 0
There is no data for this country
Statement processed.

S4L2-1
Ans :
DECLARE
v_country_name wf_countries.country_name%TYPE :=
'Canada';
v_airports wf_countries.airports%TYPE;

BEGIN
SELECT airports INTO v_airports
FROM wf_countries
WHERE country_name = v_country_name;
CASE
WHEN
v_airports BETWEEN 0 AND
100 or fewer airports. ');

100 THEN dbms_output.put_line('There are

WHEN v_airports BETWEEN 101 AND 1000 THEN dbms_output.put_line('There are


between 101 and 1,000 airports.');
WHEN
v_airports BETWEEN 1001 AND 10000 THEN dbms_output.put_line('There
are between 1,001 and 10,000 airports.');
WHEN
v_airports > 10000 THEN dbms_output.put_line('There are more than
10,000 airports');
WHEN v_airports <= 0 THEN dbms_output.put_line('The number of airports is not
available for this country');
END CASE;
END;

Result : There are between 1,001 and 10,000 airports.


Statement processed.

B.

Ans: CANADA : There are between 1,001 and 10,000 airports.


MALASIYA : There are between 101 and 1,000 airports.
United States of America : There are more than 10,000 airports
Romania : There are 100 or fewer airports.
Japan : There are between 101 and 1,000 airports.
Mongolia : There are 100 or fewer airports.
Navassa Island : The number of airports is not available for this country

S4L2- 2
DECLARE
v_country_name wf_countries.country_name%TYPE :=
'Mongolia';
v_coastline wf_countries.coastline %TYPE;
v_coastline_description VARCHAR2(50);

BEGIN
SELECT coastline INTO v_coastline
FROM wf_countries
WHERE country_name = v_country_name;

CASE
WHEN
v_coastline BETWEEN 1 AND 1000 THEN dbms_output.put_line('a small
coastline ');
WHEN
v_coastline BETWEEN 1001 AND
mid-range coastline ');
WHEN
ELSE

10000 THEN dbms_output.put_line('a

v_coastline > 10000 THEN dbms_output.put_line('a large coastline ');


dbms_output.put_line('no coastline');

END CASE;

END;

Result : a large coastline


B. CANADA : a large coastline
Jamaica

: a mid-range coastline

Mongolia : a mid-range coastline

Ukraine :
Japan

a mid-range coastline

: a large coastline

Grenada : a small coastline

S4L2-3
A:
Ans :
DECLARE
v_currency wf_countries.currency_code%TYPE:='EURO';
v_num NUMBER; v_tara VARCHAR(40);
BEGIN
SELECT COUNT(currency_code) INTO v_num FROM wf_countries;
CASE
WHEN v_num> 20 THEN DBMS_OUTPUT.PUT_LINE('More than 20 ccountries');
WHEN v_num BETWEEN 20 AND 10 THEN DBMS_OUTPUT.PUT_LINE('Between 10
and 20 countries');
WHEN v_num < 10 THEN DBMS_OUTPUT.PUT_LINE('Fewer than 10 countries');
END CASE;

END;

B.

Ecuro : More than 20 ccountries

Potrebbero piacerti anche