PL/SQL Questions and Answers – PL/SQL Exceptions

This set of PL/SQL Multiple Choice Questions & Answers (MCQs) focuses on “PL/SQL Exceptions”.

1. How many types of exceptions are present in PL/SQL?
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: a
Explanation: There are two types of exceptions present in PL/SQL. They are – System-defined exceptions and User-defined exceptions. PL/SQL offers users to tackle such exceptions through exception handling.

2. Exception handling can be performed under which of the following PL/SQL program block?
a) DECLARE
b) BEGIN
c) EXCEPTION
d) END
View Answer

Answer: c
Explanation: Exception handling is performed under the EXCEPTION block of a PL/SQL program. This block is not mandatory and depends on the user if he/she wants to include it or not. It comes after the BEGIN block.

3. Which of the following is the correct is the correct syntax for exception handling?
a)

advertisement
advertisement
WHEN exception1 THEN {
    exception1_handling_statement};
WHEN exception2 THEN {
    exception2_handling_statement};
........ 
WHEN others THEN{
    Exception_handling_statement};

b)

WHEN exception1 THEN  
    exception1_handling_statement  
WHEN exception2 THEN
    exception2_handling_statement 
........ 
WHEN others THEN 
    Exception_handling_statement

c)

advertisement
WHEN exception1 
    exception1_handling_statement  
WHEN exception2
    exception2_handling_statement 
........ 
WHEN others  
    Exception_handling_statement

d)

advertisement
exception1 THEN  
    exception1_handling_statement  
    exception2 THEN  
    exception2_handling_statement 
    ........ 
    others THEN 
    Exception_handling_statement
View Answer
Answer: b
Explanation: The correct syntax for exception handling is –

WHEN exception1 THEN  
    exception1_handling_statement  
WHEN exception2 THEN
    exception2_handling_statement 
........ 
WHEN others THEN 
    Exception_handling_statement

The default exception will be handled using WHEN others THEN. Other than that, all user-defined exceptions will be handled by their corresponding statements.

4. Which of the following command can be used to raise an exception explicitly by a user?
a) RISED
b) RAISED
c) RISE
d) RAISE
View Answer

Answer: d
Explanation: The RAISE command can be used to explicitly raise an exception by a user. Exceptions are usually raised by the database server automatically whenever there is any internal database error but they can also be done manually.

5. Raising an exception can be performed under which of the following PL/SQL program block?
a) DECLARE
b) BEGIN
c) EXCEPTION
d) END
View Answer

Answer: b
Explanation: If we are manually/explicitly raising any exception then it should come under the BEGIN block of a PL/SQL program. It is done before any exception handling process and the EXCEPTION block.

6. Which of the following syntax is correct for raising an exception explicitly?
a)

IF condition THEN 
RAISE exception_name; 
 END IF;

b)

IF condition 
RAISE exception_name; 
 END IF;

c)

IF condition THEN{ 
RAISE exception_name}; 
 END IF;

d)

IF condition THEN( 
RAISE exception_name); 
 END IF;
View Answer
Answer: a
Explanation: The correctsyntax for raising an exception explicitly is –

IF condition THEN 
RAISE exception_name; 
END IF;

Here, RAISE is the command used and exception_name is the name of the exception to be raised.

7. A user-defined exception is not automatically raised by the database server.
a) True
b) False
View Answer

Answer: a
Explanation: A user defined exception is not automatically raised by the database server and must be declared first and then raised explicitly by the user through the RAISE command.

8. Which of the following is raised when a null object is automatically assigned a value?
a) NO_DATA_FOUND
b) COLLECTION_IS_NULL
c) CASE_NOT_FOUND
d) ACCESS_INTO_NULL
View Answer

Answer: d
Explanation: The ACCESS_INTO_NULL exception is raised when a null object is automatically assigned a value. Oracle error for no data found exception is ORA –06530 and it’s SQL code is -6530. If we attempt to assign a value into a null object then this exception is invoked. We need to define the object first in which any value has to be saved.

9. Which of the following is raised when a SELECT INTO statement returns no rows?
a) CASE_NOT_FOUND
b) NOT_LOGGED_ON
c) NO_DATA_FOUND
d) ACCESS_INTO_NULL
View Answer

Answer: c
Explanation: The NO_DATA_FOUND exception is raised when a SELECT INTO statement returns no rows. Oracle error for no data found exception is ORA – 01403 and it’s SQL code is 100. If the SELECT statement cannot find any matching record according to the specified condition then this exception is invoked.

10. Which of the following is raised when PL/SQL ran out of memory or memory was corrupted?
a) VALUE_ERROR
b) TOO_MANY_ROWS
c) NO_DATA_FOUND
d) STORAGE_ERROR
View Answer

Answer: d
Explanation: The STORAGE_ERROR exception is raised when PL/SQL ran out of memory or memory was corrupted. Oracle error for storage error exception is ORA –06500 and it’s SQL code is -6500. It is usually invoked when the memory in which the result has to be saved in is full or has been corrupted. Due to the large memory size available now-days, this exception is not so frequent.

Sanfoundry Global Education & Learning Series – PL/SQL.

To practice all areas of PL/SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.