Chapter 10 Exceptions

Team-Fly    

Oracle® PL/SQL® Interactive Workbook, Second Edition
By Benjamin Rosenzweig, Elena Silvestrova
Table of Contents
Appendix A.  Answers to Self-Review Questions


Lab 10.1 Self-Review Answers

A1:

Questions

Answers

Comments

1)

C

If an exception is defined in the inner block, it can be raised in the inner block only. The outer block is not included in the scope of such an exception.

A2:

Questions

Answers

Comments

2)

B

Once an exception has been raised in the inner block and handled in the outer block, the control is passed to the enclosing environment.

A3:

Questions

Answers

Comments

3)

B

Once an exception occurs in the outer block, PL/SQL tries to find its handler in the outer block. PL/SQL will never search the inner block for the exception handler when the exception occurs in the outer block.

A4:

Questions

Answers

Comments

4)

B

In order to define an exception inside the body of the loop, you must define the PL/SQL block inside the body of the loop. Therefore, when an exception is raised, it will terminate the block, and the control will be transferred to the first executable statement after END. For example,

 FOR i IN 1..3 LOOP     BEGIN        SELECT first_name          INTO v_first_name          FROM student         WHERE student_id = 123;     EXCEPTION        WHEN NO_DATA_FOUND THEN           DBMS_OUTPUT.PUT_LINE ('Error');     END;  END LOOP; 

In this case, if there is no student corresponding to student ID 123, the exception NO_DATA_FOUND is raised. This causes the PL/SQL block to terminate. However, as long as the value of the loop counter ranges between lower and upper limits, the PL/SQL block will be executed repeatedly.

A5:

Questions

Answers

Comments

5)

B

When you want to specify the same action for various exceptions, you can combine these exceptions in the single WHEN clause. The exceptions are included in the WHEN clause with the help of the OR operator.

Lab 10.2 Self-Review Answers

A1:

Questions

Answers

Comments

1)

B

A user-defined exception is declared and raised. The exception must be declared because it is defined by a programmer and is not provided by the system. The exception must be raised explicitly because it handles violation of application rules, not Oracle rules. For example, a negative value provided by a user for the student ID violates the application rule because an ID cannot be negative, yet it does not violate Oracle rules because a number can be negative.

A2:

Questions

Answers

Comments

2)

B

 

A3:

Questions

Answers

Comments

3)

B

If a user-defined exception has been declared in the inner block, it can be raised in the inner block. However, it ceases to exist once the control is transferred to the outer block, and, as a result, it cannot be raised in the outer block. Any reference to such exception in the outer block will cause a syntax error.

A4:

Questions

Answers

Comments

4)

B

A user-defined exception behaves similarly to an Oracle built-in exception.

A5:

Questions

Answers

Comments

5)

A

The IF-THEN statement evaluates a condition that causes an application error. Once this condition yields TRUE, the RAISE statement raises a user-defined error associated with the application error. The IF-THEN statement by itself will not raise an exception. On the other hand, the RAISE statement by itself will always raise an exception.

Lab 10.3 Self-Review Answers

A1:

Questions

Answers

Comments

1)

B

Once an exception is raised in the declaration section of a block, the control is always transferred to the enclosing environment. In the case of an inner block, the control is transferred to the exception-handling section of the outer block.

A2:

Questions

Answers

Comments

2)

B

An exception encountered in the declaration section of any block causes the control to be transferred outside the block. When such a block is not enclosed by another PL/SQL block, the control is transferred to the host environment. This causes a syntax error.

A3:

Questions

Answers

Comments

3)

A

 

A4:

Questions

Answers

Comments

4)

B

Re-raising an exception causes the control to transfer outside the block. In case of an inner block, the control is transferred to the exception-handling section of the outer block.

A5:

Questions

Answers

Comments

5)

B

 


    Team-Fly    
    Top
     



    Oracle PL. SQL Interactive Workbook
    Oracle PL/SQL Interactive Workbook (2nd Edition)
    ISBN: 0130473200
    EAN: 2147483647
    Year: 2002
    Pages: 146

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net