Professional Documents
Culture Documents
Quiz s6s7
Quiz s6s7
LESSON 1
1. The following code declares a PL/SQL record with the same structure as a row of the departments table. True
or False?
DECLARE
v_dept_rec departments%ROWTYPE;
...
Mark for Review
(1) Points
True (*)
False
Correct
2. Which of the following will successfully create a record type containing two fields, and a record
variable of that type?
Mark for Review
(1) Points
TYPE person_type IS RECORD
(l_name VARCHAR2(20),
gender CHAR(1));
person_rec TYPE person_type;
TYPE person_type IS RECORD
(l_name VARCHAR2(20),
gender CHAR(1));
person_rec person_type;
(*)
TYPE person_type IS (l_name VARCHAR2(20),
gender CHAR(1));
person_rec person_type;
TYPE person_type IS (l_name VARCHAR2(20),
gender CHAR(1));
person_rec TYPE person_type;
Correct
3. Which of the following statements about user-defined PL/SQL records is NOT true?
Review
(1) Points
It is not the same as a row in a database table
It can be used as an OUT parameter in a package procedure
It can be a component of another PL/SQL record
It must contain one or more components, but all the components must have scalar datatypes (*)
It can be defined as NOT NULL
Correct
Mark for
LESSON 2
1. Which of these PL/SQL data structures can NOT store a collection?
(1) Points
A PL/SQL record (*)
An INDEX BY table of records
An INDEX BY table indexed by PLS_INTEGER
An INDEX BY table indexed by BINARY_INTEGER
Incorrect. Refer to Section 11.
2. Which of these PL/SQL data structures could store a complete copy of the employees table, i.e., 20
complete table rows?
(1) Points
A record
An INDEX BY table of records (*)
An INDEX BY table
An explicit cursor based on SELECT * FROM employees;
Incorrect. Refer to Section 11.
3. To declare an INDEX BY table, we must first declare a type and then declare a collection variable
of that type. True or False?
(1) Points
True (*)
False
Incorrect. Refer to Section 11.
4. What is the largest number of elements (i.e., records) that an INDEX BY table of records can
contain?
(1) Points
100
4096
32767
Many millions of records because a BINARY_INTEGER or PLS_INTEGER can have a very large value
(*)
None of the above
Incorrect. Refer to Section 11.
5. Which of the following successfully declares an INDEX BY table of records which could be used to
store copies of complete rows from the departments table?
(1) Points
DECLARE
TYPE t_depttab IS TABLE OF departments%TYPE
INDEX BY BINARY_INTEGER;
DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;
(*)
DECLARE
TYPE t_depttab IS INDEX BY TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;
DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEX BY NUMBER;
Correct
6. Which of the following methods can be used to reference elements of an INDEX BY table? (Choose
three.)
Mark for Review
(1) Points
(Choose all correct answers)
EXISTS (*)
FIRST (*)
COUNT (*)
PREVIOUS
DROP
Incorrect. Refer to Section 11.
SECTION 7
LESSON 1
1. Only one exception can be raised automatically during one execution of a PL/SQL block. True or False?
Mark for Review
(1) Points
True (*)
False
Correct
2. Examine the following code. Why does this exception handler not follow good practice
guidelines? (Choose two.)
DECLARE
v_dept_name departments.department_name%TYPE;
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;
Mark for Review
(1) Points
(Choose all correct answers)
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. (*)
Handle specific named exceptions where possible, instead of relying on WHEN OTHERS.
Correct
6. Which of the following is NOT an advantage of including an exception handler in a PL/SQL
block?
Mark for Review
(1) Points
Prevents errors from occurring (*)
Code is more readable because error-handling routines can be written in the same block in which the
error occurred
Prevents errors from being propagated back to the calling environment
Avoids costly and time-consuming correction of mistakes
Incorrect. Refer to Section 7 Lesson 1.
7. 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;
Mark for Review
(1) Points
True (*)
False
Correct
8. Which of the following best describes a PL/SQL exception?
Mark for Review
(1) Points
A user enters an invalid password while trying to log on to the database.
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
LESSON 2
The code will not execute because PRAGMA EXCEPTION_INIT must be coded in the DECLARE
section. (*)
The code will not execute because the syntax of the INSERT statement is wrong.
Correct
4. Which type(s) of exception MUST be explicitly raised by the PL/SQL programmer?
Review
(1) Points
User-defined exceptions. (*)
Mark for
TOO_MANY_ROWS
e_sal_too_high EXCEPTION; (*)
ZERO_DIVIDE
DUP_VAL_ON_INDEX
Correct
6. 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
7. How would you trap Oracle Server exception ORA-01403: no data found?
(1) Points
WHEN NO DATA FOUND THEN ...
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
12. A PL/SQL block executes and an Oracle Server exception is raised. Which of the following
contains the text message associated with the exception?
(1) Points
SQLCODE
SQLERRM (*)
SQL%MESSAGE
SQL_MESSAGE_TEXT
Correct
LESSON 3
False (*)
Correct
2. You want to display your own error message to the user. What is the correct syntax to do this?
Mark for Review
(1) Points
RAISE_APPLICATION_ERROR(20001, 'My own message');
RAISE_APPLICATION_ERROR('My own message', -20001);
RAISE application_error;
RAISE_APPLICATION_ERROR (-20001, 'My own message'); (*)
Correct
3. What is wrong with the following code?
BEGIN
UPDATE employees SET salary = 20000
WHERE job_id = 'CLERK';
IF SQL%ROWCOUNT = 0 THEN
RAISE NO_DATA_FOUND; -- Line A
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXCEPTION (*)
NUMBER
None of the above
Correct
6. What is a user-defined exception?
Mark for Review
(1) Points
A predefined Oracle server exception such as NO_DATA_FOUND.
An exception which has a predefined Oracle error number but no predefined name.
An exception handler which the user (the programmer) includes in the EXCEPTION section.
An exception which is not raised automatically by the Oracle server, but must be declared and raised
explicitly by the PL/SQL programmer. (*)
Correct
7. 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?
Review
(1) Points
Raise, Handle, Declare
Handle, Raise, Declare
Declare, Raise, Handle (*)
The steps can be performed in any order.
Correct
8. How are user-defined exceptions raised ?
(1) Points
By PRAGMA EXCEPTION_INIT
LESSON 4
Mark for
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;
Mark for Review
(1) Points
25
30 (*)
35
40
100
Correct
2. 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;
Mark for Review
(1) Points
Message 1
Message 3
Message 4
Message 1
Message 4
(*)
Message 1
An unhandled exception will be propagated back to the calling environment.
None of the above
Correct
3. Non-predefined Oracle Server errors (associated with Oracle error numbers by PRAGMA
EXCEPTION_INIT) can be declared and raised in inner blocks and handled in outer blocks. True or False?
Mark for Review
(1) Points
True
False (*)
Correct
4. What will happen when the following code is executed?
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
RAISE e_excep2; END;
END;
Mark for Review
(1) Points
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
5. 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;
Mark for Review
(1) Points
The code will execute successfully and 'Outer Raised' will be displayed.
The code will propagate the e_outer_excep back to the calling environment (Application Express).
The code will fail to compile because e_inner_excep cannot be referenced in the outer block. (*)
The code will fail to compile because e_inner_excep was declared but never RAISEd.
Correct
6. Predefined Oracle Server exceptions such as NO_DATA_FOUND can be raised automatically in
inner blocks and handled in outer blocks. True or False?
(1) Points
True (*)
False
Correct