Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions