Handling Exceptions: Paste The Modified Code Here
Handling Exceptions: Paste The Modified Code Here
Handling Exceptions: Paste The Modified Code Here
Handling Exceptions
1.
DECLARE
v_jobid employees.job_id%TYPE;
BEGIN
SELECT job_id
INTO v_jobid
FROM employees
WHERE department_id = 80;
END;
In Application Express modify the code to fix the problem with an EXCEPTION Handler
Paste the modified code here
DECLARE
v_jobid employees.job_id%TYPE;
BEGIN
SELECT job_id
INTO v_jobid
FROM employees
WHERE department_id = 80;
exception
When too_many_rows then
DBMS_OUTPUT.PUT_LINE (' Your select statement retrieved
multiple rows. Consider using a cursor.');
END;
2. Run the following PL/SQL block, which tries to insert a new row (with department_id = 50)
into the departments table.
BEGIN
INSERT INTO departments(department_id, department_name, manager_id, location_id)
VALUES(50, 'Management Information Systems', 100,1500);
DBMS_OUTPUT.PUT_LINE('The new department was inserted');
END;
A. What happened when you run this code and why?
B.
3. Run the following PL/SQL block, which tries to SELECT all the employees in a specific
department. Run it three times, using department_ids 10, 20 and 30. What happens and why?
DECLARE
v_employee_id employees.employee_id%TYPE;
v_last_name employees.last_name%TYPE;
BEGIN
SELECT employee_id, last_name INTO v_employee_id, v_last_name
FROM employees
WHERE department_ID = 10;
END;
A. What happens and why?
No data in one and too many rows on the other
B. In Application Express modify the code to include exceptions to handle errors ALL errors
Paste the modified code here
DECLARE
v_employee_id employees.employee_id%TYPE;
v_last_name
employees.last_name%TYPE;
BEGIN
SELECT employee_id, last_name INTO v_employee_id, v_last_name
FROM employees
WHERE department_ID = 20;
exception
When too_many_rows then
DBMS_OUTPUT.PUT_LINE (' Your select statement retrieved
multiple rows. Consider using a cursor.');
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE ('no data');
END;