SQL Exception Handling MCQ Questions and Answers
Exception Handling MCQs : This section focuses on the "Exception Handling" in SQL. These Multiple Choice Questions (mcq) should be practiced to improve the SQL skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. How many types of exception are there in sql?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : A
Explanation: There are two types of exceptions : System-defined exceptions
and User-defined exceptions
2. Name the exception which is raised when a null object is automatically assigned a value?
A. CASE_NOT_FOUND
B. COLLECTION_IS_NULL
C. ACCESS_INTO_NULL
D. DUP_VAL_ON_INDEX
View Answer
Ans : C
Explanation: ACCESS_INTO_NULL : It is raised when a null object is automatically assigned a value.
3. What is oracle error code for exception COLLECTION_IS_NULL?
A. "06530"
B. "06592"
C. "06531"
D. "01722"
View Answer
Ans : C
Explanation: oracle error code for exception COLLECTION_IS_NULL is 06531.
4. What is true about PROGRAM_ERROR?
A. It is raised when a SELECT INTO statement returns no rows.
B. It is raised when PL/SQL has an internal problem.
C. It is raised when PL/SQL ran out of memory or memory was corrupted.
D. It is raised when a SELECT INTO statement returns more than one row.
View Answer
Ans : B
Explanation: PROGRAM_ERROR : It is raised when PL/SQL has an internal problem.
5. An exception is an error condition during a program execution.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: An exception is an error condition during a program execution
6. The default exception will be handled using?
A. Default Keyword
B. WHEN THEN Keyword
C. WHEN Keyword
D. WHEN others THEN Keyword
View Answer
Ans : D
Explanation: The default exception will be handled using WHEN others THEN.
7. Which of the following exception raised when an arithmetic, conversion, truncation, or sizeconstraint error occurs?
A. ZERO_DIVIDE
B. VALUE_ERROR
C. TOO_MANY_ROWS
D. SELF_IS_NULL
View Answer
Ans : B
Explanation: VALUE_ERROR : It is raised when an arithmetic, conversion, truncation, or sizeconstraint error occurs.
8. What is the sql error code for SELF_IS_NULL?
A. "-6504"
B. "-30625"
C. "-1422"
D. "-6502"
View Answer
Ans : B
Explanation: SELF_IS_NULL errorcode(-30625) : It is raised when a member method is invoked, but the instance of the object type was not initialized.
9. Point out the correct statement.
A. While executing some DML Statement like INSERT, DELETE, UPDATE we can handle the error for checking proper output
B. If transaction fails, then we need to commit – This can be done by error handling
C. If transaction succeeds, then we need to rollback – This can be done by error handling
D. All of the above
View Answer
Ans : A
Explanation: SQL Server also has an exception model to handle exceptions and errors that occurs in T-SQL statements.
10. Which statements can be checked for handling errors.
A. DDL
B. TCL
C. DML
D. TTL
View Answer
Ans : C
Explanation: DML statements can be checked for handling errors.
11. Which Exception is also known as Oracle named exception handler?
A. Predefined Exception
B. Internal Exception
C. User defined Exception
D. None of the above
View Answer
Ans : A
Explanation: A predefined exception is the one which is executed whenever a program violates any database rule. Example of this type of exception can be the exception NO_DATA_FOUND.
12. When creating a function, in which section will you typically find a return key word?
A. Header Only
B. Declarative
C. Executable and Header
D. Executable and exception handling
View Answer
Ans : C
Explanation: The return keyword is an executable statement. It is mandatory to write this keyword in a function.
13. Which of the following returns the current error message text?
A. SQLERRM
B. SQLCODE
C. Both A and B
D. None of the above
View Answer
Ans : A
Explanation: Using this function the associated error message with the most recent raised error exception is displayed. The exception handling section will display this function.
14. For a user-defined exception, SQLCODE returns 1, and SQLERRM returns ___________.
A. 1
B. User-defined Exception
C. 0
D. Predefined Exception
View Answer
Ans : B
Explanation: The SQLCODE is useful in an exception handler. SQLCODE is useful to the other exception handlers as it lets you identify the internal exception which is raised. The SQLERRM will return the user defined exception.
15. Which of the following is true?
A. The keyword All is a shorthand way to refer to all warning messages.
B. In internal exception oracle raises the exception for you implicitly. You still need to declare the exception and handle it, but you don’t need to raise it.
C. An exception handling block is used so that we can avoid the errors in the program
D. All of the above
View Answer
Ans : D
Explanation: All of the above are TRUE.
16. Which of the following is a global variable for error handling?
A. "@@ERRORS"
B. "@ERRORS"
C. "@@ERR"
D. "@@ERRORS"
View Answer
Ans : A
Explanation: @@ERROR is one of the basic error handling mechanisms in SQL Server.
17. ERROR_SEVERITY() returns the ________level of the error.
A. State number
B. Full text
C. Severity
D. None of the above
View Answer
Ans : C
Explanation: ERROR_SEVERITY() returns the severity level of the error.
18. Which of the following is an Error function used within CATCH block?
A. ERROR_STATUS()
B. ERROR_STATE()
C. ERROR_MSG()
D. None of the above
View Answer
Ans : B
Explanation: ERROR_STATE() returns the state number of the error.
19. Exception handling is possible in SQL Server using _____________
A. FINAL
B. FINALLY
C. THROW
D. THROWS
View Answer
Ans : C
Explanation: Generates an error message and initiates error processing for the session.
20. Which of the following benefit does Exception handling with the TRY and CATCH blocks provide?
A. Exceptions provide a mechanism to signal errors directly rather than using some side effects
B. Exceptions can be seen by the programmer and checked during the compilation process
C. Exceptions provide a clean way to check for errors without cluttering code
D. All of the above
View Answer
Ans : D
Explanation: Exception handling using the TRY and CATCH statements is the common way that modern programming languages like C# and Java treat errors.
Discussion