Section 7 Quiz
Section 7 Quiz
1. Using two nested blocks, a TOO_MANY_ROWS exception is raised within the inner
block. Which of the following exception handlers will successfully handle the Mark for Review
exception? (1) Points
Correct
True
False (*)
Correct
3. Which of the following are good practice guidelines for exception handling? (Choose
three.) Mark for Review
(1) Points
Correct
5. Examine the following code. Why does this exception handler not follow good practice
guidelines? (Choose two.) Mark for Review
(1) Points
DECLARE
v_dept_name departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_dept_name FROM departments
WHERE department_id = 75;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('A select returned more than one row');
END;
Correct
7. Examine the followiing code. Which exception handlers would successfully trap
the exception which will be raised when this code is executed? (Choose two.) Mark for Review
(1) Points
DECLARE
CURSOR emp_curs IS SELECT * FROM employees;
v_emp_rec emp_curs%ROWTYPE;
BEGIN
FETCH emp_curs INTO v_emp_rec;
OPEN emp_curs;
CLOSE emp_curs;
EXCEPTION ...
END;
8. Examine the following code. The UPDATE statement will raise an ORA-02291
exception. Mark for Review
(1) Points
BEGIN
UPDATE employees SET department_id = 45;
EXCEPTION
WHEN OTHERS THEN
INSERT INTO error_log_table VALUES (SQLCODE);
END;
The code will fail because we cannot use functions like SQLCODE directly
in a SQL statement. (*)
The code will execute and insert error number 02291 into error_log_table.
The code will fail because we access error message numbers by using
SQLERRNUM, not SQLCODE.
The code will fail because SQLCODE has not been declared.
Correct
All of these.
Predefined Oracle server errors such as TOO_MANY_ROWS
Non-predefined Oracle server errors such as ORA-01203
User-defined exceptions (*)
10. Examine the following code fragment. At Line A, you want to raise an
exception if the fetched salary value is greater than 30000. How can you do Mark for Review
this? (1) Points
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 100;
IF v_salary > 30000 THEN
-- Line A
END IF;
...
Test for WHEN OTHERS in the exception section, because WHEN OTHERS
traps all exceptions.
Use RAISE_APPLICATION_ERROR to raise an exception explicitly. (*)
Test for WHEN VALUE_TOO_HIGH in the exception section.
Define an EXCEPTION variable and associate it with an Oracle Server
error number using PRAGMA EXCEPTION_INIT.
Correct
11. Examine the following code. At
Line A, you want to raise an Mark for Review
exception if the employee's (1) Points
manager_id is null. What kind
of exception is this?
DECLARE
v_mgr_id
employees.manager_id%TYPE;
BEGIN
SELECT manager_id INTO
v_mgr_id FROM employees
WHERE employee_id =
100;
IF v_mgr_id IS NULL THEN
-- Line A
END IF;
...
A NO_DATA_FOUND exception
A constraint violation
A predefined Oracle Server exception
A user-defined exception (*)
A non-predefined Oracle server exception
Correct
Correct
A and C
B and C (*)
C
B
A and B
Correct