0% found this document useful (0 votes)
82 views3 pages

m1s2 Reference

1. The document provides 3 PL/SQL code blocks with missing elements to complete database queries and condition checks. 2. The first block finds a country's population from the countries table and checks if it is over 1 billion. 3. The second block enhances the first to handle null and zero populations. 4. The third block finds a country's airports and returns a message based on the quantity.

Uploaded by

wasdwasdwasd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views3 pages

m1s2 Reference

1. The document provides 3 PL/SQL code blocks with missing elements to complete database queries and condition checks. 2. The first block finds a country's population from the countries table and checks if it is over 1 billion. 3. The second block enhances the first to handle null and zero populations. 4. The third block finds a country's airports and returns a message based on the quantity.

Uploaded by

wasdwasdwasd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

[ M1S2 - CODE REFERENCE]

DATABASE SYSTEM WITH ADMINISTRATION


---------------------------------------------------------------------------------------------------------------------------------------------------------
1.) Write a PL/SQL block to find the population of a given country in the countries table. Display a message
indicating whether the population is greater than or less than 1 billion (1,000,000,000).

Supply the missing elements in order to satisfy the above statement.

declare

vpop ___________.population%type;

begin

select population into ______ from countries

where ____________ = &cid;

if ______________ then

dbms_output.put_line('Population less than 1B');

else

dbms_output.put_line('Population greater than 1B');

_______

end;
2.) Modify the code given in #1 so that it handles all the following cases:
▪ Population is greater than 1 billion.
▪ Population is greater than 0.
▪ Population is 0.
▪ Population is null. (Display: No data for this country.)

Assumptions:
- Variable vpop has been properly declared at the declaration section.
- Implicit cursor has been created to store a value to vpop.

declare

vpop is properly declared here. . . . . .

begin

. . . . . . . .

. . . . . . . .

if vpop = ___(1)____ then

dbms_output.put_line('No data for this country');

elsif ____(2)____then

dbms_output.put_line('Population = 0');

elsif vpop > 0 then

dbms_output.put_line('Population greater than 0');

if _____________ then

dbms_output.put_line('Population greater than 1B');

end if;

end if;

end;
3.) Write a PL/SQL block to find the number of airports from the countries table for a supplied country_name.
Based on this number, display a customized message as follows:

Supply the missing elements of the given below to satisfy the above statement.

declare

v_aport countries.airports%type;

vmesg __________(50);

begin

select _________ into v_aport from countries

where upper(country_name)= ________('&cname');

case

when v_aport between 0 and 100 then

vmesg := 'There are 100 or fewer airports';

when v_aport between 101 and 1000 then

vmesg := 'There are between 101 and 1,000 airports';

when v_aport between 1001 and 10000 then

vmesg := 'There are between 1001 and 10,000 airports';

when v_aport ________ then

vmesg := 'There are more than 10,000 airports';

else

vmesg := 'The number of airports is not available for

this country';

end;

dbms_output.put_line(vmesg);

end;

You might also like