You are on page 1of 7

Database System with Administration

TECHNICAL ASSESSMENT

M1, M2, M3

Name: Lexia Panogalinog

Section:

Professor:

Database System with Administration Page 1 of 3


REQUIREMENTS:
 Screen shots of your code and output from Oracle Cloud - SQL Developer Web.
 Paste your screen shots after each question.
 Your screen shots must show your worskspace name.
 Codes and output must be readable from the screen shots.

PART-1. Control Structures. (10pts)

1.) 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:

Use a CASE statement to process your comparisons. (5 marks)

Database System with Administration Page 2 of 3


2.) Using any of the PL/SQL looping statement, write a PL/SQL block to display the country_id and country_name values
from the WF_COUNTRIES table for country_id whose values range from 51 through
55. Test your variable to see when it reaches 55. EXIT the loop after you have displayed the 5 countries. (5 marks)

Database System with Administration Page 3 of 3


PART-2. Explicit Cursor and Record Structure (10 Points)

Create a PL/SQL block that fetches and displays the six employees with the highest salary. For each of these
employees, display the first name, last name, job id, and salary. Order your output so that the employee with the
highest salary is displayed first. Use %ROWTYPE and the explicit cursor attribute
%ROWCOUNT.

DECLARE

 CURSOR employees_cursor IS 

 SELECT *

 FROM employees

 ORDER BY salary DESC;

 v_emp_rec employees_cursor%ROWTYPE;

BEGIN

 OPEN employees_cursor;

 LOOP

  FETCH employees_cursor INTO v_emp_rec;

  EXIT WHEN employees_cursor%ROWCOUNT > 6;

  DBMS_OUTPUT.PUT_LINE(v_emp_rec.first_name || ' ' || v_emp_rec.last_name || ' ' || v_emp_rec.job_id || ' '


|| v_emp_rec.salary);

  END LOOP;

 CLOSE employees_cursor;

END;

Database System with Administration Page 4 of 3


PART-3. Explicit Cursor and User Defined Structure (15 Points)

Write a PL/SQL block to read through rows in the countries table for all countries in region 5 (South America region).
Country name must be entered by the user. For each selected country, display the country_name, national_holiday_date,
and national_holiday_name. Use a record structure (user defined) to hold all the columns selected from the
countries table.

DECLARE

 CURSOR countries_cur IS 

 SELECT country_name, national_holiday_date, national_holiday_name

 FROM wf_countries

 WHERE region_id = 5;

 v_countries countries_cur%ROWTYPE;

BEGIN

 OPEN countries_cur;

 LOOP

  FETCH countries_cur INTO v_countries;

  EXIT WHEN countries_cur%NOTFOUND;

  DBMS_OUTPUT.PUT_LINE(v_countries.country_name || ' ' || v_countries.national_holiday_date || ' ' ||


v_countries.national_holiday_name);

  END LOOP;

 CLOSE countries_cur;

END;

Database System with Administration Page 5 of 3


PART-4. Exception Handling. (15 Points)

A. Add an exception handler to the following code to trap the following predefined Oracle Server errors:
NO_DATA_FOUND, TOO_MANY_ROWS, and DUP_VAL_ON_INDEX. (5 pts)

DECLARE
v_language_id languages.language_id%TYPE;
v_language_name languages.language_name%TYPE;
BEGIN
SELECT language_id, language_name INTO v_language_id, v_language_name FROM languages WHERE
LOWER(language_name) LIKE '<substring%>'; -- for example 'ab%'

INSERT INTO languages(language_id, language_name) VALUES(80, null); END;

DECLARE v_language_id
languages.language_id%TYPE;
v_language_name languages.language_name%TYPE;
BEGIN
SELECT language_id, language_name INTO v_language_id, v_language_name
FROM languages
WHERE LOWER(language_name) LIKE '<substring%>'; -- for example 'ab%'
INSERT INTO languages(language_id, language_name)
VALUES(80, null);
exception
when NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No se encontro dato, se controlo el error');
when TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('Muchas filas, se
controlo el error');
WHEN DUP_VAL_ON_INDEX THEN
DBMS_OUTPUT.PUT_LINE('dup val on index, se controlo el error');
END;

Database System with Administration Page 6 of 3


Note: Test your block twice using each of the following language substrings: ba, ce. There are several
language_names beginning with “Ba,” but none beginning with “Ce”.

Aparece el error
NO_DATA_FOUND
y
TOO_MANY_ROWS

B. Now test your block a third time using substring: al. There is exactly one language_name beginning with
“Al”. Note that language_id 80 (Arabic) already exists. Explain the output. (5 pts)

Aparece el error NO_DATA_FOUND

C. Now (keeping the substring as “al”), add a non_predefined exception handler to trap then encountered oracle
exception code. Rerun the code and explain the result. (5 pts)

DECLARE v_language_id
languages.language_id%TYPE
;
v_language_name languages.language_name%TYPE;
e_null_not_allowed
EXCEPTION;
PRAGMA EXCEPTION_INIT (e_null_not_allowed,
-
01400);
BEGIN
SELECT language_id, language_name INTO v_language_id, v_language_name
FROM languages
WHERE LOWER(language_name) LIKE 'Al%';
--
for example 'ab%'
INSERT INTO languages(language_id, language_name)
VALUES(80, null);
exception
when e_null_not_allowed THEN
DBMS_OUTPUT.PUT_LINE('Se controlo el error');
END;
Imprimio no data found

Database System with Administration Page 7 of 3

You might also like