Halaman

Tuesday, August 20, 2019

Answer Section 7 Quiz Database Programming with PL/SQL 2019 Learner - English


Section 7


While a PL/SQL block is executing, more than one exception can occur at the same time. True or False? 
                                                                               
                                               
                TRUE


                                               
                FALSE (*)

                                                                               
                                                               
Which of the following EXCEPTION sections are constructed correctly? (Choose two.)    
                                                                               
                                                (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 OTHERS THEN statement_2;
    WHEN NO_DATA_FOUND THEN statement_1;
END;

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


                                                                               
The following EXCEPTION section is constructed correctly. True or False?
EXCEPTION
    WHEN ZERO_DIVIDE OR TOO_MANY_ROWS OR NO_DATA_FOUND
       THEN statement_1;
          statement_2;
             WHEN OTHERS
       THEN statement_3;
END;
                                                               
                                               
                True (*)

                                               
                False

                                                                               
                                                               
Which of the following is NOT an advantage of including an exception handler in a PL/SQL block?                                                                
                                               
                Prevents errors from being propagated back to the calling environment

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

                                               
                Prevents errors from occurring (*)

                                               
                Avoids costly and time-consuming correction of mistakes

                                                                               
                                                               
Which kind of error can NOT be handled by PL/SQL?       
                                                                               
                                               
                User-defined errors

                                               
                Non-predefined Oracle Server errors

                                               
                Predefined Oracle Server errors

                                               
                Syntax errors (*)


Examine the following code fragment. At Line A, you want to raise an exception if the fetched salary value is greater than 30000. How can you do this?
DECLARE
    v_salary employees.salary%TYPE;
BEGIN
    SELECT salary INTO v_salary FROM employees
       WHERE employee_id = 100;
    IF v_salary > 30000 THEN
       -- Line A
    END IF;
...
                                                                               
                                               
                Use RAISE_APPLICATION_ERROR to raise an exception explicitly. (*)

                                               
                Test for WHEN OTHERS in the exception section, because WHEN OTHERS traps all exceptions.

                                               
                Define an EXCEPTION variable and associate it with an Oracle Server error number using PRAGMA EXCEPTION_INIT.

                                               
                Test for WHEN VALUE_TOO_HIGH in the exception section.

                                                                               
                                                               
Which of the following is NOT a predefined Oracle Server error?           
                                                                               
                                               
                e_sal_too_high EXCEPTION; (*)

                                               
                TOO_MANY_ROWS

                                               
                DUP_VAL_ON_INDEX

                                               
                ZERO_DIVIDE

                                               
                NO_DATA_FOUND

                                                                               
                                                               
How can you retrieve the error code and error message of any Oracle Server exception?               
                                                                               
                                               
                By using RAISE_APPLICATION_ERROR

                                               
                By using the functions SQLCODE and SQLERRM (*)

                                               
                By using the functions SQLCODE and SQLERR

                                               
                By defining an EXCEPTION variable and using PRAGMA EXCEPTION_INIT

                                                                               
                                                               
Examine the followiing code. Which exception handlers would successfully trap the exception which will be raised when this code is executed? (Choose two.)
DECLARE
    CURSOR emp_curs IS SELECT * FROM employees;
    v_emp_rec emp_curs%ROWTYPE;
BEGIN
    FETCH emp_curs INTO v_emp_rec;
    OPEN emp_curs;
    CLOSE emp_curs;
EXCEPTION ...
END;
                                                                               
                                                (Choose all correct answers)      
                                                                               
                                               
                WHEN INVALID_CURSOR (*)

                                               
                WHEN CURSOR_NOT_OPEN

                                               
                WHEN INVALID_FETCH

                                               
                WHEN OTHERS (*)

                                               
                WHEN NO_DATA_FOUND

                                                                               
                                                               
What will happen when the following code is executed?
DECLARE
    e_outer_excep EXCEPTION;
BEGIN
    DECLARE
       e_inner_excep EXCEPTION;
    BEGIN
       RAISE e_outer_excep;
    END;
EXCEPTION
    WHEN e_outer_excep THEN
       DBMS_OUTPUT.PUT_LINE('Outer raised');
    WHEN e_inner_excep THEN
       DBMS_OUTPUT.PUT_LINE('Inner raised');
END;

                                                                               
                                               
                The code will propagate the e_outer_excep back to the calling environment.

                                               
                The code will execute successfully and 'Outer Raised' will be displayed.

                                               
                The code will fail to compile because e_inner_excep was declared but never RAISEd.

                                               
                The code will fail to compile because e_inner_excep cannot be referenced in the outer block. (*)


There are three employees in department 90. What will be displayed when this code is executed?
DECLARE
    v_last_name employees.last_name%TYPE;
BEGIN
    DBMS_OUTPUT.PUT_LINE('Message 1');
    BEGIN
       SELECT last_name INTO v_last_name
          FROM employees WHERE department_id = 90;
       DBMS_OUTPUT.PUT_LINE('Message 2');
    END;
    DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION
    WHEN OTHERS THEN
       DBMS_OUTPUT.PUT_LINE('Message 4');
END;

                                                                               
                                               
                Message 1

                                               
                None of these.

                                               
                Message 1
Message 3
Message 4

                                               
                Message 1
Message 4
(*)


                                               
                An unhandled exception will be propagated back to the calling environment.

                                                                               
                                                               
What will be displayed when the following code is executed?
DECLARE
    e_myexcep EXCEPTION;
BEGIN
    DBMS_OUTPUT.PUT_LINE('Message 1');
    RAISE e_myexcep;
    DBMS_OUTPUT.PUT_LINE('Message 2');
EXCEPTION
    WHEN e_myexcep THEN
       DBMS_OUTPUT.PUT_LINE('Message 3');
       RAISE e_myexcep;
       DBMS_OUTPUT.PUT_LINE('Message 4');
END;

                                                                               
                                               
                The code will execute but will return an unhandled exception to the calling environment.
(*)


                                               
                The code will not execute because it contains at least one syntax error.

                                               
                Message 1
Message 3

                                               
                Message 1
Message 2
Message 3
Message 4

                                               
                Message 1
Message 3
Message 4

                                                                               
                                                               
How are user-defined exceptions raised ?          
                                                                               
                                               
                By RAISE exception_name; (*)

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

                                               
                By DECLARE e_my_excep EXCEPTION;

                                               
                By PRAGMA EXCEPTION_INIT

                                                                               
                                                               
A user-defined exception is raised by using:        
                                                                               
                                               
                PRAGMA EXCEPTION_INIT

                                               
                RAISE exception-name; (*)

                                               
                RAISE(error_number, exception_name);

                                               
                FLAG exception_name;

                                                                               
                                                               
The following three steps must be performed to use a user-defined exception: - Raise the exception - Handle the exception - Declare the exception In what sequence must these steps be performed?  
                                                                               
                                               
                Declare, Raise, Handle (*)

                                               
                Raise, Handle, Declare

                                               
                The steps can be performed in any order.

                                               
                Handle, Raise, Declare

No comments:

Post a Comment

Final Exam Java Programming 2019 Learner - English

Final Exam