Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q 5 . ( 3 0 points ) This question will use table Locations. It is useful to insert a record of the error into

Q5.(30 points) This question will use table Locations.
It is useful to insert a record of the error into a table for future review when an exception happens. The code below will create a table to store the error information,
DROP TABLE log_error; -- in case you have that table created, otherwise ignore this.
CREATE TABLE log_error (
Occur_date DATE DEFAULT SYSDATE,
Username VARCHAR2(15) DEFAULT USER,
Err_code NUMBER,
Err_msg VARCHAR2(255));
** Here, we use "SYSDATE" for Occur_date, "USER" for username.
According to the scripts (for creating the tables) provided on D2L,
ALTER TABLE departments
ADD (... CONSTRAINT dept_loc_fk FOREIGN KEY (location_id)
REFERENCES locations (location_id));
the location_id in the Departments table is a foreign key referencing to location_id in the Locations table, thus the program cannot simply delete a location if there is/are department(s) in that location (ID).
The following Select statements will display which location ID are used or not.
select distinct location_id from departments; -- list all locations that are used now
select location_id from locations -- list all locations that are defined,
select location_id from locations minus
select distinct location_id from departments; -- list all locations that are not currently used.
Write a PL/SQL block that will run two SQL delete commands. First time, delete a location with ID 1900; second time, delete the location with ID 1800.
In the executable section, you will define an exception section with OTHERS handler, that will catch up any unexpected error. In that OTHERS handler, your program will use SQLCODE and SQLERRM to get the error number and error message. Your program will execute an insert command to add a record into the log_error table when an error occurs.
After you run the PL/SQL block, you need to run a SQL statement separately to display the contents of the log_error table, that should include the record just inserted when an error was caught in the last program.
To keep the data as that were created, it is recommended to rollback these deletions after you have run the select from log_error table and before you leave the program.

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

Identify and control your anxieties

Answered: 1 week ago

Question

Understanding and Addressing Anxiety

Answered: 1 week ago