You are on page 1of 6

Section 7 Quiz

(Answer all questions in this section)

1. Which of the following will successfully return a user-defined error message? Mark for Review
(1) Points

RAISE_APPLICATION_ERROR('Error Raised',-22001);
RAISE_APPLICATION_ERROR(-29001,'Error Raised');
RAISE_APPLICATION_ERROR(-20257,'Error raised'); (*)
RAISE_APPLICATION_ERROR('Error Raised',-20257);

Incorrect. Refer to Section 7 Lesson 3.

2. What is wrong with the following code? Mark for Review


BEGIN (1) Points
UPDATE employees SET salary = 20000
WHERE job_id = 'CLERK';
IF SQL%ROWCOUNT = 0 THEN
RAISE NO_DATA_FOUND; -- Line A
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No employee was updated');
END;

Line A should be: HANDLE NO_DATA_FOUND


NO_DATA_FOUND has not been DECLAREd.
You cannot explicitly raise predefined Oracle Server errors such as
NO_DATA_FOUND.
You cannot use SQL%ROWCOUNT in conditional control statements such as IF or
CASE.
Nothing is wrong; the code will execute correctly. (*)

Correct

3. The following three steps must be performed to use a user-defined exception: - Raise Mark for Review
the exception - Handle the exception - Declare the exception In what sequence must
these steps be performed? (1) Points

Handle, Raise, Declare


Declare, Raise, Handle (*)
Raise, Handle, Declare
The steps can be performed in any order.

Correct
4. How are user-defined exceptions raised ? Mark for Review
(1) Points

None of these. They are raised automatically by the Oracle server.


By PRAGMA EXCEPTION_INIT
By DECLARE e_my_excep EXCEPTION;
By RAISE exception_name; (*)

Correct

5. Which of the following are examples of predefined Oracle Server errors? (Choose Mark for Review
three.)
(1) Points

(Choose all correct answers)

E_INSERT_EXCEP
ZERO_DIVIDE (*)
TOO_MANY_ROWS (*)
OTHERS
NO_DATA_FOUND (*)

Incorrect. Refer to Section 7 Lesson 2.


6. A PL/SQL
block Mark for Review
executes (1) Points
and an
Oracle
Server
exception
is raised.
Which of
the
following
contains
the text
message
associated
with the
exception?

SQL%MESSAGE
SQLCODE
SQL_MESSAGE_TEXT
SQLERRM (*)

Correct
7. An attempt to update an employee's salary to a negative value will violate a Mark for Review
check constraint and raise an ORA-02290 exception. Which of the following is a
correct definition of a handler for this exception? (1) Points

DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(-02290,e_sal_excep);
DECLARE
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);
e_sal_excep EXCEPTION;
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);

(*)
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,02290);
DECLARE
e_sal_excep EXCEPTION;
PRAGMA_EXCEPTION_INIT(e_sal_exception,-02290);

Correct

8. You cannot use SQLCODE or SQLERRM directly in an SQL statement. Instead, Mark for Review
you must assign their values to local variables, then use the variables in the SQL
statement (1) Points

True (*)
False

Correct

9. Which one of the following events would implicitly raise an exception? Mark for Review
(1) Points

A database constraint is violated. (*)


A SELECT statement returns exactly one row.
An UPDATE statement modifies no rows.
The PL/SQL programmer mis-spells the word BEGIN as BEGAN.

Correct

10. Which of the following are good practice guidelines for exception handling? Mark for Review
(Choose three.)
(1) Points

(Choose all correct answers)


Allow exceptions to propagate back to the calling environment.
Test your code with different combinations of data to see what potential
errors can happen. (*)
Include a WHEN OTHERS handler as the first handler in the exception
section.
Handle specific named exceptions where possible, instead of relying on
WHEN OTHERS. (*)
Use an exception handler whenever there is any possibility of an error
occurring. (*)

Correct
11. Which of Mark for Review
the
following (1) Points
best
describes
a PL/SQL
exception?

An error occurs during the execution of the block, which disrupts the
normal operation of the program. (*)
The programmer forgets to declare a cursor while writing the PL/SQL
code.
A compile-time error occurs because the PL/SQL code references a non-
existent table.
A user enters an invalid password while trying to log on to the database.

Correct

12. Examine the following code. Why does this exception handler not follow good Mark for Review
practice guidelines? (Choose two.)
(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;

(Choose all correct answers)

The exception handler should test for the named exception


NO_DATA_FOUND. (*)
The exception handler should COMMIT the transaction.
You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.
department_id 75 does not exist in the departments table.
The exception section should include a WHEN TOO_MANY_ROWS
exception handler. (*)
Correct

13. Which of these exceptions can be handled by an EXCEPTION section in a Mark for Review
PL/SQL block?
(1) Points

None of these.
A SELECT statement returns more than one row.
Any other kind of exception that can occur within the block
A SELECT statement returns no rows.
All of these. (*)

Incorrect. Refer to Section 7 Lesson 1.

14. No employees exist in department 75. What will be displayed when this code is Mark for Review
executed?
(1) Points
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('A');
BEGIN
SELECT last_name INTO v_last_name
FROM employees WHERE department_id = 75;
DBMS_OUTPUT.PUT_LINE('B');
END;
DBMS_OUTPUT.PUT_LINE('C');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('D');
END;

A
C
D
A
B
D
None of these.
A
D

(*)
A

Incorrect. Refer to Section 7 Lesson 4.

15. What will be displayed when the following code is executed? Mark for Review
(1) Points
<< outer>>
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 10;
DECLARE
v_myvar NUMBER := 200;
BEGIN
outer.v_myvar := 20;
v_myvar := v_myvar / 0; -- this raises a ZERO_DIVIDE error
outer.v_myvar := 30;
END;
v_myvar := 40;
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE(v_myvar);
END;

200
20 (*)
40
30
10

Correct

You might also like