Sei sulla pagina 1di 8

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.What is the correct syntax to associate an exception named EXCEPNAME with the non-
predefined Oracle Server error ORA-02292? Mark for Review
(1) Points
SQLCODE (-2292, excepname);

PRAGMA EXCEPTION_INIT (excepname, -2292) (*)

RAISE_APPLICATION_ERROR (-2292, excepname);

WHEN (-2292, excepname) THEN …

Correct

2.Which of these exceptions would need to be raised explicitly by the PL/SQL programmer?
Mark for Review
(1) Points
A check constraint is violated.

A SELECT statement returns more than one row.

OTHERS

A SQL UPDATE statement does not update any rows. (*)

A row is FETCHed from a cursor while the cursor is closed.

Correct

3.Which kinds of exceptions are raised implicitly (i.e., automatically)? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)
Predefined Oracle Server errors such as NO_DATA_FOUND (*)

All errors

User-defined errors

Non-predefined Oracle Server errors such as ORA-01400 (*)

Correct

4.How would you trap Oracle Server exception ORA-01403: no data found?
Mark for Review
(1) Points
WHEN NO DATA FOUND THEN ...

WHEN ORA-01403 THEN ...

WHEN SQL%ROWCOUNT=0 THEN ...


WHEN NO_DATA_FOUND THEN ... (*)
Correct

5.An ORA-1400 exception is raised if an attempt is made to insert a null value into a NOT
NULL column. DEPARTMENT_ID is the primary key of the DEPARTMENTS table. What will Mark for Review
happen when the following code is executed? (1) Points

DECLARE
e_not_null EXCEPTION;
BEGIN
PRAGMA EXCEPTION_INIT(e_not_null, -1400);
INSERT INTO departments (department_id, department_name)
VALUES(null, 'Marketing');
EXCEPTION
WHEN e_not_null THEN
DBMS_OUTPUT.PUT_LINE('Cannot be null');
END;
The exception will be raised and "Cannot be null" will be displayed.

The code will not execute because the syntax of the INSERT statement is wrong.

The code will not execute because PRAGMA EXCEPTION_INIT must be coded in the
DECLARE section. (*)
The code will not execute because the syntax of PRAGMA EXCEPTION_INIT is
wrong.
Correct
Section 7 Quiz

(Answer all questions in this section)

6. Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL block?


Mark for Review
(1) Points

None of these.

A SELECT statement returns no rows

Any other kind of exception that can occur within the block

All of these. (*)

An attempt is made to divide by zero

Correct

7. Which of the following EXCEPTION sections are constructed correctly? (Choose two.)
Mark for Review
(1) Points

(Choose all correct answers)

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;

(*)
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
END;

(*)
EXCEPTION
WHEN OTHERS THEN statement_2;
WHEN NO_DATA_FOUND THEN statement_1;
END;

Correct

8. Examine the following code. Why does this exception handler not follow good practice
guidelines? Mark for Review
(1) Points
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;

employee_id 999 does not exist in the employees table.

The exception handler should COMMIT the transaction.

The exception handler should test for the named exception NO_DATA_FOUND. (*)

You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.

Correct

9. Which of the following is NOT an advantage of including an exception handler in a


PL/SQL block? Mark for Review
(1) Points

Prevents errors from occurring (*)

Prevents errors from being propagated back to the calling environment

Avoids costly and time-consuming correction of mistakes

Code is more readable because error-handling routines can be written in the same
block in which the error occurred
Correct

10.Predefined Oracle Server exceptions such as NO_DATA_FOUND can be raised


automatically in inner blocks and handled in outer blocks. True or False? Mark for Review
(1) Points

True (*)

False

Correct

Section 7 Quiz

(Answer all questions in this section)

11.What will be displayed when the following code is executed?


Mark for Review
<<outer>> (1) Points
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;

40

10

20 (*)
200

30

Correct

12.How are user-defined exceptions raised ?


Mark for Review
(1) Points

By PRAGMA EXCEPTION_INIT

By DECLARE e_my_excep EXCEPTION;

By RAISE exception_name; (*)

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

Correct

13.User-defined exceptions must be declared explicitly by the programmer, but then are
raised automatically by the Oracle Server. True or False? Mark for Review
(1) Points

TRUE

FALSE (*)

Correct

14.Department-id 99 does not exist. What will be displayed when the following code is
executed? Mark for Review
(1) Points
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;

ORA-01403: No Data Found

ORA-01403: No Data Found ORA-20201: Department does not exist

ORA-20201: Department does not exist (*)

None of these.

Correct

15.A user-defined exception must be declared as a variable of data type EXCEPTION. True
or False? Mark for Review
(1) Points

TRUE (*)

FALSE

Correct

Potrebbero piacerti anche