Answered step by step
Verified Expert Solution
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
Q 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 logerror; in case you have that table created, otherwise ignore this.
CREATE TABLE logerror
Occurdate DATE DEFAULT SYSDATE,
Username VARCHAR DEFAULT USER,
Errcode NUMBER,
Errmsg VARCHAR;
Here, we use "SYSDATE" for Occurdate, "USER" for username.
According to the scripts for creating the tables provided on DL
ALTER TABLE departments
ADD CONSTRAINT deptlocfk FOREIGN KEY locationid
REFERENCES locations locationid;
the locationid in the Departments table is a foreign key referencing to locationid in the Locations table, thus the program cannot simply delete a location if there isare departments in that location ID
The following Select statements will display which location ID are used or not.
select distinct locationid from departments; list all locations that are used now
select locationid from locations list all locations that are defined,
select locationid from locations minus
select distinct locationid from departments; list all locations that are not currently used.
Write a PLSQL block that will run two SQL delete commands. First time, delete a location with ID ; second time, delete the location with ID
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 logerror table when an error occurs.
After you run the PLSQL block, you need to run a SQL statement separately to display the contents of the logerror 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 logerror table and before you leave the program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started