Test: Section 7 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 7 Quiz
(Answer all questions in this section)
1. No employees are in department_id 99. What output will be
displayed when the following code is executed?
DECLARE
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM employees WHERE department_id = 99;
IF v_count = 0 THEN
RAISE NO_DATA_FOUND;
DBMS_OUTPUT.PUT_LINE('No employees found');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Department 99 is empty');
END;
Mark for Review
(1) Points
No employees found Department 99 is empty
Department 99 is empty (*)
The block will fail because you cannot explicitly RAISE a predefined Oracle
Server error such as NO_DATA_FOUND
No employees found
Correct Correct
2. You want to display your own error message to the user. What is
the correct syntax to do this? Mark for Review
(1) Points
RAISE_APPLICATION_ERROR('My own message', -20001);
RAISE application_error;
RAISE_APPLICATION_ERROR(20001, 'My own message');
RAISE_APPLICATION_ERROR (-20001, 'My own message'); (*)
Correct Correct
3. Department-id 99 does not exist. What will be displayed when the
following code is executed?
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_deptname
FROM departments WHERE department_id = 99;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20201,'Department does not exist');
END;
Mark for Review
(1) Points
ORA-01403: No Data Found ORA-20201: Department does not exist
ORA-01403: No Data Found
ORA-20201: Department does not exist (*)
None of these.
Correct Correct
4. The following three steps must be performed to use a user-defined
exception: - Raise the exception - Handle the exception - Declare the exception In
what sequence must these steps be performed? Mark for Review
(1) Points
Handle, Raise, Declare
The steps can be performed in any order.
Declare, Raise, Handle (*)
Raise, Handle, Declare
Correct Correct
5. The following code does not violate any constraints and will not
raise an ORA-02292 error. What will happen when the code is executed?
BEGIN
DECLARE
e_constraint_violation EXCEPTION;
PRAGMA EXCEPTION_INIT(e_constraint_violation, -2292);
BEGIN
DBMS_OUTPUT.PUT_LINE('Inner block message');
END;
EXCEPTION
WHEN e_constraint_violation THEN
DBMS_OUTPUT.PUT_LINE('Outer block message');
END;
Mark for Review
(1) Points
The code will fail because the exception is declared in the inner block but
is referenced in the outer block. (*)
'Inner block message' will be displayed.
The code will fail because line 4 should read: PRAGMA EXCEPTION_INIT(-2292,
e_constraint_violation);
'Outer block message' will be displayed.
Correct Correct
Page 1 of 3 Next Summary
Test: Section 7 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 7 Quiz
(Answer all questions in this section)
6. There are three employees in department 90. What will be
displayed when this code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('Message 1');
BEGIN
SELECT last_name INTO v_last_name
FROM employees WHERE department_id = 90;
DBMS_OUTPUT.PUT_LINE('Message 2');
END;
DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Message 4');
END;
Mark for Review
(1) Points
An unhandled exception will be propagated back to the calling environment.
None of these.
Message 1
Message 4
(*)
Message 1
Message 1
Message 3
Message 4
Correct Correct
7. How can you retrieve the error code and error message of any
Oracle Server exception? Mark for Review
(1) Points
By defining an EXCEPTION variable and using PRAGMA EXCEPTION_INIT
By using the functions SQLCODE and SQLERR
By using RAISE_APPLICATION_ERROR
By using the functions SQLCODE and SQLERRM (*)
Incorrect Incorrect. Refer to Section 7 Lesson 2.
8. Which of the following are examples of predefined Oracle Server
errors? (Choose three.) Mark for Review
(1) Points
(Choose all correct answers)
OTHERS
TOO_MANY_ROWS (*)
NO_DATA_FOUND (*)
ZERO_DIVIDE (*)
E_INSERT_EXCEP
Correct Correct
9. Which of the following is NOT a predefined Oracle Server error?
Mark for Review
(1) Points
TOO_MANY_ROWS
NO_DATA_FOUND
DUP_VAL_ON_INDEX
ZERO_DIVIDE
e_sal_too_high EXCEPTION; (*)
Correct Correct
10. Which kind of error can NOT be handled by PL/SQL? Mark for
Review
(1) Points
Non-predefined Oracle Server errors
Syntax errors (*)
Predefined Oracle Server errors
User-defined errors
Correct Correct
Previous Page 2 of 3 Next Summary
Test: Section 7 Quiz
Review your answers, feedback, and question scores below. An asterisk (*) indicates
a correct answer.
Section 7 Quiz
(Answer all questions in this section)
11. Examine the following code. What message or messages will be
displayed when this code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
v_number NUMBER := 27;
BEGIN
v_number := v_number / 0;
SELECT last_name INTO v_last_name FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows were found');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Attempt to divide by zero');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;
Mark for Review
(1) Points
An error occurred
Attempt to divide by zero (*)
No message will be displayed
No rows were found
Attempt to divide by zero No rows were found
Correct Correct
12. Which of these exceptions can be handled by an EXCEPTION section
in a PL/SQL block? Mark for Review
(1) Points
A SELECT statement returns no rows
All of these. (*)
An attempt is made to divide by zero
None of these.
Any other kind of exception that can occur within the block
Correct Correct
13. Which of the following best describes a PL/SQL exception? Mark
for Review
(1) Points
An error occurs during execution which disrupts the normal operation of the
program. (*)
The programmer makes a spelling mistake while writiing the PL/SQL code.
A user enters an invalid password while trying to log on to the database.
A DML statement does not modify any rows.
Correct Correct
14. Which of the following EXCEPTION sections is constructed
correctly? (Choose three.) Mark for Review
(1) Points
(Choose all correct answers)
EXCEPTION
WHEN OTHERS THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
END;
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
END;
(*)
EXCEPTION
WHEN TOO_MANY_ROWS THEN statement_1;
END;
(*)
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
WHEN OTHERS THEN statement_3;
END;
EXCEPTION
WHEN OTHERS THEN statement_1;
END;
(*)
Correct Correct
15. Which of the following best describes a PL/SQL exception? Mark
for Review
(1) Points
The programmer forgets to declare a cursor while writing the PL/SQL code.
A user enters an invalid password while trying to log on to the database.
A compile-time error occurs because the PL/SQL code references a non-existent
table.
An error occurs during the execution of the block, which disrupts the normal
operation of the program. (*)
Correct Correct
Previous Page 3 of 3 Summary