Question: In this week's exercise you will be practicing PL/SQL as a database programming language. Given the two following table definitions below (see DDL): CREATE TABLE

In this week's exercise you will be practicing PL/SQL as a database programming language. Given the two following table definitions below (see DDL):

CREATE TABLE COUNTRY ( Country_Code char(3) NOT NULL, Country_Name varchar2(200) NOT NULL, CONSTRAINT COUNTRY_pk PRIMARY KEY (Country_Code) );

CREATE TABLE POPULATION ( Country_Code char(3) NOT NULL, Year number(4) NOT NULL, Total_Population integer NOT NULL, CONSTRAINT POPULATION_pk PRIMARY KEY (Country_Code,Year) );

ALTER TABLE POPULATION ADD CONSTRAINT POPULATION_COUNTRY_FK FOREIGN KEY (Country_Code) REFERENCES COUNTRY (Country_Code);

You must write two database functions (NOT procedures):

  1. POPULATION_AVERAGE: must return the average population for a given country in a period of time, given the following parameters
    • country_name
      • must be validated and an exception raised when country name is NOT valid
    • year_from and year_to as the [begin,end] (all inclusive) for the period to be considered when calculating average
      • raise an exception if period is invalid [no data available] for that period
  2. POPULATION_CHANGE: must return the percentage (%) of change in the population for a given country in a period of time, given the following parameters
    • country_name
      • must be validated and an exception raised when country name is NOT valid
    • year_from and year_to as the [begin,end] (all inclusive) for the period to be considered when calculating the % of change
      • result can be positive (when population has increased) or negative (when population has decreased)
      • raise an exception if period is invalid [no data available] for that period

*** You must populate the tables in order to test your solution

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!