Beruflich Dokumente
Kultur Dokumente
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section)
1. Examine the following code. Why does this exception handler not follow good Mark for
practice guidelines? (Choose two.)
DECLARE Review
v_dept_name departments.department_name%TYPE; (1) Points
BEGIN
SELECT department_name INTO v_dept_name FROM departments
WHERE department_id = 75;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('A select returned more than one row');
END;
Correct
2. Which of the following are NOT good practice guidelines for exception Mark for
handling? (Choose two.)
Review
(1) Points
Test your code with different combinations of data to see what potential
errors can happen.
Use an exception handler whenever there is any possibility of an error
occurring.
Include a WHEN OTHERS handler as the first handler in the exception
section. (*)
Allow exceptions to propagate back to the calling environment. (*)
Correct
3. Which of these exceptions can be handled by an EXCEPTION section in a Mark for
PL/SQL block?
Review
(1) Points
Any other kind of exception that can occur within the block
Correct
4. Which of the following EXCEPTION sections are constructed correctly? Mark for
(Choose three.)
Review
(1) Points
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
END;
(*)
EXCEPTION
WHEN TOO_MANY_ROWS THEN statement_1;
END;
(*)
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_1;
WHEN NO_DATA_FOUND THEN statement_2;
END;
Correct
5. Which of the following best describes a PL/SQL exception? Mark for
Review
(1) Points
An error occurs during the execution of the block, which disrupts the
normal operation of the program. (*)
A compile-time error occurs because the PL/SQL code references a non-
existent table.
The programmer forgets to declare a cursor while writing the PL/SQL
code.
Correct
6. The following EXCEPTION section is constructed correctly. True or False? Mark for
EXCEPTION
WHEN ZERO_DIVIDE OR TOO_MANY_ROWS OR NO_DATA_FOUND Review
THEN statement_1; (1) Points
statement_2;
WHEN OTHERS
THEN statement_3;
END;
True (*)
False
Correct
7. Which of the following is NOT an advantage of including an exception handler Mark for
in a PL/SQL block?
Review
(1) Points
Correct
8. Only one exception can be raised automatically during one execution of a Mark for
PL/SQL block. True or False?
Review
(1) Points
True (*)
False
Correct
Test: Quiz: Trapping Oracle Server Exceptions
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section)
1. Which type(s) of exception MUST be explicitly raised by the PL/SQL Mark for
programmer?
Review
(1) Points
Correct
2. Examine the following code. At Line A, you want to raise an exception if the Mark for
employee's manager_id is null. What kind of exception is this?
DECLARE Review
v_mgr_id employees.manager_id%TYPE; (1) Points
BEGIN
SELECT manager_id INTO v_mgr_id FROM employees
WHERE employee_id = 100;
IF v_mgr_id IS NULL THEN
-- Line A
END IF;
...
A constraint violation
A NO_DATA_FOUND exception
Correct
3. There are no employees whose salary is less than 2000. Which exception Mark for
handlers would successfully trap the exception which will be raised when
the following code is executed? (Choose two.)
Review
(1) Points
DECLARE
v_mynum NUMBER := 10;
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count FROM employees
WHERE salary < 2000;
v_mynum := v_mynum / v_count;
EXCEPTION ...
END;
NO_DATA_FOUND
ZERO_DIVIDE (*)
SQL%ROWCOUNT = 0
OTHERS (*)
OTHER
Correct
4. Which one of the following events would implicitly raise an exception? Mark for
Review
(1) Points
Correct
5. An ORA-1400 exception is raised if an attempt is made to insert a null value Mark for
into a NOT NULL column. DEPARTMENT_ID is the primary key of the
DEPARTMENTS table. What will happen when the following code is
executed? Review
(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.
Correct
6. A PL/SQL block executes and an Oracle Server exception is raised. Which of Mark for
the following contains the text message associated with the exception?
Review
(1) Points
SQLCODE
SQLERRM (*)
SQL%MESSAGE
SQL_MESSAGE_TEXT
Correct
7. Examine the following code. The UPDATE statement will raise an ORA-02291 Mark for
exception.
BEGIN Review
UPDATE employees SET department_id = 45; (1) Points
EXCEPTION
WHEN OTHERS THEN
INSERT INTO error_log_table VALUES (SQLCODE);
END;
The code will execute and insert error number 02291 into
error_log_table.
The code will fail because SQLCODE has not been declared.
The code will fail because we access error message numbers by using
SQLERRNUM, not SQLCODE.
The code will fail because we cannot use functions like SQLCODE
directly in a SQL statement. (*)
Correct
Review
(1) Points
Syntax errors (*)
User-defined errors
Correct
9. How would you trap Oracle Server exception ORA-01403: no data found? Mark for
Review
(1) Points
Correct
10. Which of the following best describes a predefined Oracle Server error? Mark for
Review
(1) Points
Has a standard Oracle error number but must be declared and named
by the PL/SQL programmer
Has a standard Oracle error number and a standard name which can be
referenced in the EXCEPTION section (*)
Is associated with an Oracle error number using PRAGMA
EXCEPTION_INIT
Is not raised automatically but must be declared and raised explicitly
by the PL/SQL programmer
Correct
11. Which of the following is NOT a predefined Oracle Server error? Mark for
Review
(1) Points
NO_DATA_FOUND
TOO_MANY_ROWS
ZERO_DIVIDE
DUP_VAL_ON_INDEX
Correct
12. What is the correct syntax to associate an exception named EXCEPNAME Mark for
with the non-predefined Oracle Server error ORA-02292?
Review
(1) Points
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section)
Review
(1) Points
True
False (*)
Correct
BEGIN
UPDATE employees SET salary = 20000 Review
WHERE job_id = 'CLERK'; (1) Points
IF SQL%ROWCOUNT = 0 THEN
RAISE NO_DATA_FOUND; -- Line A
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No employee was updated');
END;
Correct
Review
(1) Points
BOOLEAN
VARCHAR2
EXCEPTION (*)
NUMBER
Correct
Review
(1) Points
Correct
5. The following three steps must be performed to use a user-defined exception: Mark for
- Raise the exception - Handle the exception - Declare the exception In what
sequence must these steps be performed?
Review
(1) Points
Correct
6. What will be displayed when the following code is executed? Mark for
DECLARE
e_myexcep EXCEPTION; Review
BEGIN (1) Points
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;
Message 1
Message 3
Message 1
Message 3
Message 4
Message 1
Message 2
Message 3
Message 4
The code will not execute because it contains at least one syntax error.
The code will execute but will return an unhandled exception to the
calling environment.
(*)
Correct
Review
(1) Points
By PRAGMA EXCEPTION_INIT
None of the above. They are raised automatically by the Oracle server.
Correct
8. You want to display your own error message to the user. What is the correct Mark for
syntax to do this?
Review
(1) Points
RAISE_APPLICATION_ERROR(20001, 'My own message');
RAISE application_error;
Correct
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section)
1. What will happen when the following code is executed? Mark for
DECLARE
e_outer_excep EXCEPTION;
BEGIN Review
DECLARE (1) Points
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 execute successfully and 'Outer Raised' will be displayed.
Correct
2. What will happen when the following code is executed? Mark for
DECLARE
e_excep1 EXCEPTION; Review
e_excep2 EXCEPTION; (1) Points
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
RAISE e_excep2; END;
END;
It will fail to compile because you cannot have a subblock inside an
exception section.
It will fail to compile because e_excep1 is out of scope in the subblock.
It will fail to compile because you cannot declare more than one
exception in the same block.
It will compile successfully and return an unhandled e_excep2 to the
calling environment. (*)
Correct
3. What will be displayed when the following code is executed? Mark for
<<outer>>
DECLARE Review
v_myvar NUMBER; (1) Points
BEGIN
v_myvar := 25;
DECLARE
v_myvar NUMBER := 100;
BEGIN
outer.v_myvar := 30;
v_myvar := v_myvar / 0;
outer.v_myvar := 35;
END;
v_myvar := 40;
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE(v_myvar);
END;
25
30 (*)
35
40
100
Correct
4. There are three employees in department 90. What will be displayed when Mark for
this code is executed?
DECLARE Review
v_last_name employees.last_name%TYPE; (1) Points
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
Message 3
Message 4
Message 1
Message 4
(*)
Message 1
Correct
5. Predefined Oracle Server exceptions such as NO_DATA_FOUND can be raised Mark for
automatically in inner blocks and handled in outer blocks. True or False?
Review
(1) Points
True (*)
False
Correct
6. Non-predefined Oracle Server errors (associated with Oracle error numbers Mark for
by PRAGMA EXCEPTION_INIT) can be declared and raised in inner blocks and
handled in outer blocks. True or False?
Review
(1) Points
True
False (*)
Correct