You are on page 1of 29

Test: Section 5 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 5 Quiz

(Answer all questions in this section)

1.What is one of the advantages of using parameters with a cursor?


Mark for Review
(1) Points

You can declare the cursor FOR UPDATE.

You can use a single cursor to fetch a different set of rows each time the
cursor is opened. (*)

You do not need to DECLARE the cursor at all.

You can use a cursor FOR loop.

It will execute much faster than a cursor without parameters.

Correct

2.Examine the following declaration of a cursor with a parameter. What should


Mark for Review
be coded at Point A?
(1) Points
DECLARE
CURSOR emp_curs(-- Point A --) IS
SELECT * FROM employees
WHERE job_id = p_job_id;

p_job_id VARCHAR2 (*)


ST_CLERK'

p_job_id VARCHAR2(25)

p_job_id

job_id VARCHAR2

Correct

3.Which of the following is a good reason to declare and use multiple cursors in
Mark for Review
a single PL/SQL block?
(1) Points

Multiple cursors use less memory than a single cursor.

Multiple cursors allow us to fetch rows from two or more related tables
without using a JOIN. (*)

Multiple cursors can be opened many times, while a single cursor can be
opened only once.

Multiple cursors are the only way to use cursors with parameters.

Multiple cursors improve performance. They are faster than using a single
cursor.

Correct

4.Which of the following is NOT allowed when using multiple cursors with
Mark for Review
parameters?
(1) Points

Declaring a cursor FOR UPDATE

None of these--they are all allowed. (*)

Using cursor FOR loops


Declaring a cursor based on a join

OPENing more than one cursor at the same time

Correct

5.Which of these constructs can be used to fetch multiple rows from a cursor's
Mark for Review
active set?
(1) Points

A CASE statement

A basic loop which includes OPEN, FETCH, and CLOSE statements

A basic loop which includes FETCH and EXIT WHEN statements (*)

An IF .... ELSE statement

Correct

Test: Section 5 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 5 Quiz

(Answer all questions in this section)

6. There are 8 countries in REGION_ID 13 (Central America). What will happen


Mark for Review
when the following code is executed?
(1) Points
DECLARE
CURSOR country_curs IS SELECT country_name FROM
wf_countries
WHERE region_id = 13;
v_country_name wf_countries.country_name%TYPE;
BEGIN
OPEN country_curs;
WHILE country_curs%FOUND
LOOP
FETCH country_curs INTO v_country_name;
DBMS_OUTPUT.PUT_LINE(v_country_name);
END LOOP;
CLOSE country_curs;
END;

The last seven rows will be fetched and displayed.

The block will execute, but no rows will be displayed. (*)

The block will fail because you can not use a WHILE loop with an explicit
cursor.

Eight rows will be fetched and displayed successfully.

None of the these.

Correct

7. After a cursor has been closed, it can be opened again in the same PL/SQL
Mark for Review
block. True or False?
(1) Points

TRUE (*)

FALSE

Correct

8. Which statement correctly places the employee id and last name into the
Mark for Review
stated variables?
(1) Points
DECLARE
CURSOR emp_cursor IS
SELECT employee_id, last_name FROM employees
WHERE department_id = 30;
v_empno employees.employee_id%TYPE;
v_lname employees.last_name%TYPE;
BEGIN
OPEN emp_cursor;
-- Point A
...

FETCH emp_cursor.employee_id, emp_cursor.last_name INTO


v_empno, v_lname;

GET emp_cursor INTO v_empno, v_lname;

GET emp_cursor.employee_id, emp_cursor.last_name INTO v_empno,


v_lname;

FETCH emp_cursor INTO v_empno, v_lname; (*)

Correct

9. Consider the following cursor:


Mark for Review
(1) Points
CURSOR c IS
SELECT e.last_name, e.salary, d.department_name
FROM employees e JOIN departments d
USING(department_id)
WHERE e.last_name='Smith'
FOR UPDATE;

When the cursor is opened and rows are fetched, what is locked?

The whole EMPLOYEES and DEPARTMENTS tables are locked.

Nothing is locked because the cursor was not declared with NOWAIT.

The whole EMPLOYEES table is locked.

Each 'Smith' row is locked and Smith's matching rows in DEPARTMENTS


are locked. No other rows are locked in either table. (*)
In the EMPLOYEES table, only the 'Smith' rows are locked. Nothing in the
DEPARTMENTS table is locked.

Correct

10.A cursor is declared as:


Mark for Review
(1) Points
CURSOR c IS SELECT * FROM departments FOR UPDATE;

After opening the cursor and fetching some rows, you want to delete
the most recently fetched row. Which of the following will do this
successfully?

DELETE FROM c WHERE CURRENT OF c;

DELETE FROM departments WHERE c%ROWCOUNT = 1;

None of these.

DELETE FROM c WHERE CURRENT OF departments;

DELETE FROM departments WHERE CURRENT OF c; (*)

Correct

Test: Section 5 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 5 Quiz

(Answer all questions in this section)


11.If the rows you attempt to reserve using FOR UPDATE have already been
Mark for Review
locked by another session and you use the NOWAIT option, what is the
(1) Points
outcome?

The server will wait until the locks have been released by the other user.

An Oracle server error occurs. (*)

Your rows will override the other user's lock and your block will execute
successfully.

The block executes successfully with no errors.

Correct

12.Look at the following code:


Mark for Review
(1) Points
DECLARE
CURSOR emp_cursor IS SELECT * FROM employees;
BEGIN
FOR emp_record IN emp_cursor LOOP
DBMS_OUTPUT.PUT_LINE( --Point A -- );
END LOOP;
END;

To display the salary of an employee, what code should you write at


Point A?

employees.salary

emp_record.employees.salary

TO_CHAR(salary)

emp_cursor.salary

emp_record.salary (*)

Correct
13.A cursor FOR loop using a subquery can shorten code length when compared
Mark for Review
to an explicit cursor declaration. True or False?
(1) Points

True (*)

False

Correct

14.The following cursor has been declared:


Mark for Review
(1) Points
CURSOR emp_curs IS
SELECT first_name, last_name, job_id, salary
FROM employees;

Which of the following correctly declares a composite record with the


same structure as the cursor?

emp_rec emp_rec%ROWTYPE;

emp_rec emp_curs%TYPE;

emp_rec emp_curs%ROWTYPE; (*)

emp_rec cursor%ROWTYPE;

Correct

15.Look at the following code:


Mark for Review
(1) Points
DECLARE
CURSOR emp_cursor IS
SELECT employee_id, last_name, salary FROM employees;
v_empcurs emp_cursor%ROWTYPE;

What is the data type of V_EMPCURS?


Record (*)

Scalar

Cursor

Row

Correct

Test: Section 6 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6 Quiz

(Answer all questions in this section)

1.Which of the following will successfully create a record type containing two
Mark for Review
fields, and a record variable of that type?
(1) Points

TYPE person_type IS RECORD


(l_name VARCHAR2(20),
gender CHAR(1));
person_rec person_type;

(*)
TYPE person_type IS RECORD

(l_name VARCHAR2(20),
gender CHAR(1));
person_rec TYPE 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

2.The following code declares a PL/SQL record with the same structure as a row
Mark for Review
of the departments table. True or False?
(1) Points
DECLARE
v_dept_rec departments%ROWTYPE;
...

True (*)

False

Correct

3.You can use %ROWTYPE with tables and views.


Mark for Review
(1) Points

True (*)

False

Correct

4.Which of the following statements about user-defined PL/SQL records is NOT


Mark for Review
true?
(1) Points

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.

It is not the same as a row in a database table.

It can be used as an OUT parameter in a package procedure.

Correct

5.Consider the following code:


Mark for Review
(1) Points
DECLARE
TYPE dept_info_type IS RECORD
(department_id departments.department_id%TYPE,
department_name departments.department_name%TYPE);
TYPE emp_dept_type IS RECORD
(first_name employees.first_name%TYPE,
last_name employees.last_name%TYPE),
dept_info dept_info_type);

v_emp_dept_rec emp_dept_type;

How many fields can be addressed in v_emp_dept_rec?

one

three

four (*)

two

Correct

Test: Section 6 Quiz


Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6 Quiz

(Answer all questions in this section)

6. Which of the following successfully declares an INDEX BY table of records


Mark for Review
which could be used to store copies of complete rows from the departments
(1) Points
table?

DECLARE
TYPE t_depttab IS TABLE OF departments%TYPE
INDEX BY BINARY_INTEGER;

DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEXED BY NUMBER;

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 BINARY_INTEGER;

(*)

Incorrect. Refer to Section 6 Lesson 2.

7. To declare an INDEX BY table, we must first declare a type and then declare a
Mark for Review
collection variable of that type. True or False?
(1) Points

True (*)

False

Correct
8. An INDEX BY TABLE primary key cannot be negative.
Mark for Review
(1) Points

True

False (*)

Correct

9. Which of these PL/SQL data structures can NOT store a collection?


Mark for Review
(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

Correct

10.Which of the following methods can be used to reference elements of an


Mark for Review
INDEX BY table? (Choose three.)
(1) Points

(Choose all correct answers)

COUNT (*)

FIRST (*)
DROP

EXISTS (*)

PREVIOUS

Test: Section 6 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 6 Quiz

(Answer all questions in this section)

11.Which of these PL/SQL data structures could store a complete copy of the
Mark for Review
employees table, i.e., 20 complete table rows?
(1) Points

An INDEX BY table of records (*)

An explicit cursor based on SELECT * FROM employees;

A record

An INDEX BY table

Correct

12.In an INDEX BY table of records the record can be


Mark for Review
_______________________.
(1) Points

Either one. (*)


%ROWTYPE

a user-defined record

Incorrect. Refer to Section 6 Lesson 2.

13.An INDEX BY TABLE must have a primary key.


Mark for Review
(1) Points

True (*)

False

Correct

14.Identify the valid collection types:


Mark for Review
(1) Points

(Choose all correct answers)

INDEX BY TABLE OF RECORDS (*)

INDEX BY TABLE (*)

INDEX BY VIEW

INDEX BY TABLE OF ROWS

Correct
15.An INDEX BY TABLE type can only have one data field.
Mark for Review
(1) Points

True (*)

False

Correct

Test: Section 7 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7 Quiz

(Answer all questions in this section)

1.Examine the following code. Why does this exception handler not follow good
Mark for Review
practice guidelines? (Choose two.)
(1) Points
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;

(Choose all correct answers)

department_id 75 does not exist in the departments table.


The exception section should include a WHEN TOO_MANY_ROWS
exception handler. (*)

The exception handler should test for the named exception


NO_DATA_FOUND. (*)

The exception handler should COMMIT the transaction.

You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.

Incorrect. Refer to Section 7 Lesson 1.

2.Which of the following are good practice guidelines for exception handling?
Mark for Review
(Choose three.)
(1) Points

(Choose all correct answers)

Include a WHEN OTHERS handler as the first handler in the exception


section.

Test your code with different combinations of data to see what potential
errors can happen. (*)

Allow exceptions to propagate back to the calling environment.

Use an exception handler whenever there is any possibility of an error


occurring. (*)

Handle specific named exceptions where possible, instead of relying on


WHEN OTHERS. (*)

Incorrect. Refer to Section 7 Lesson 1.

3.The following EXCEPTION section is constructed correctly. True or False?


Mark for Review
(1) Points
EXCEPTION
WHEN NO_DATA_FOUND OR TOO_MANY_ROWS
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;

TRUE (*)

FALSE

Correct

4.While a PL/SQL block is executing, more than one exception can occur at the
Mark for Review
same time. True or False?
(1) Points

TRUE

FALSE (*)

Correct

5.Which of the following will successfully return a user-defined error message?


Mark for Review
(1) Points

RAISE_APPLICATION_ERROR(-20257,'Error raised'); (*)

RAISE_APPLICATION_ERROR(-29001,'Error Raised');

RAISE_APPLICATION_ERROR('Error Raised',-20257);

RAISE_APPLICATION_ERROR('Error Raised',-22001);

Correct
Test: Section 7 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7 Quiz

(Answer all questions in this section)

6. The following line of code is correct. True or False?


Mark for Review
RAISE_APPLICATION_ERROR(-21001,'My error message');
(1) Points

True

False (*)

Correct

7. Department-id 99 does not exist. What will be displayed when the following
Mark for Review
code is executed?
(1) Points
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_deptname
FROM departments WHERE department_id = 99;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20201,'Department does not
exist');
END;

None of these.

ORA-01403: No Data Found

ORA-20201: Department does not exist (*)


ORA-01403: No Data Found ORA-20201: Department does not exist

Correct

8. What is a?
Mark for Review
(1) Points

An exception which is not raised automatically by the Oracle server, but


must be declared and raised explicitly by the PL/SQL programmer. (*)

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.

A predefined Oracle server exception such as NO_DATA_FOUND.

Correct

9. Which of the following are examples of predefined Oracle Server errors?


Mark for Review
(Choose three.)
(1) Points

(Choose all correct answers)

OTHERS

NO_DATA_FOUND (*)

E_INSERT_EXCEP

ZERO_DIVIDE (*)

TOO_MANY_ROWS (*)
Correct

10.Which kind of error can NOT be handled by PL/SQL?


Mark for Review
(1) Points

Predefined Oracle Server errors

Syntax errors (*)

Non-predefined Oracle Server errors

User-defined errors

Correct

Test: Section 7 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 7 Quiz

(Answer all questions in this section)

11.Examine the following code. At Line A, you want to raise an exception if the
Mark for Review
employee's manager_id is null. What kind of exception is this?
(1) Points
DECLARE
v_mgr_id employees.manager_id%TYPE;
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 predefined Oracle Server exception

A user-defined exception (*)

A NO_DATA_FOUND exception

A non-predefined Oracle server exception

Correct

12.Examine the following code. What message or messages will be displayed


Mark for Review
when this code is executed?
(1) Points
DECLARE
v_last_name employees.last_name%TYPE;
v_number NUMBER := 27;
BEGIN
v_number := v_number / 0;
SELECT last_name INTO v_last_name FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows were found');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Attempt to divide by zero');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;

No message will be displayed

Attempt to divide by zero No rows were found

An error occurred

No rows were found

Attempt to divide by zero (*)


Correct

13.Examine the following code fragment. At Line A, you want to raise an


Mark for Review
exception if the fetched salary value is greater than 30000. How can you do
(1) Points
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;
...

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.

Use RAISE_APPLICATION_ERROR to raise an exception explicitly. (*)

Test for WHEN VALUE_TOO_HIGH in the exception section.

Correct

14.Predefined Oracle Server exceptions such as NO_DATA_FOUND can be raised


Mark for Review
automatically in inner blocks and handled in outer blocks. True or False?
(1) Points

True (*)

False

Correct
15.What will happen when the following code is executed?
Mark for Review
(1) Points
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN
BEGIN
RAISE e_excep2;
END;
END;

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. (*)

It will fail to compile because you cannot have a subblock inside an


exception section.

Correct

Test: Section 8 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 8 Quiz

(Answer all questions in this section)

1.Suppose you set up a parameter with an explicit IN mode. What is true about
Mark for Review
that parameter?
(1) Points
It cannot have a DEFAULT value.

It acts like a constant (its value cannot be changed inside the


subprogram). (*)

It must have a DEFAULT value.

It inherits its type from the matching OUT parameter.

It must be the same type as the matching OUT parameter.

Correct

2.What are the three parameter modes for procedures?


Mark for Review
(1) Points

IN, OUT, IN OUT (*)

R(ead), W(rite), A(ppend)

CONSTANT, VARIABLE, DEFAULT

COPY, NOCOPY, REF

Correct

3.Which kind of parameters cannot have a DEFAULT value?


Mark for Review
(1) Points

W(rite)

OUT (*)

IN
CONSTANT

R(ead)

Correct

4.What are the types of parameter modes?


Mark for Review
(1) Points

CONSTANT, VARIABLE, DEFAULT

IN, OUT, IN OUT (*)

LOCAL, GLOBAL, BOTH

CHARACTER, NUMBER, DATE, BOOLEAN

Correct

5.The following procedure has been created:


Mark for Review
(1) Points
CREATE OR REPLACE PROCEDURE defproc
(A IN NUMBER := 50,
B IN NUMBER,
C IN NUMBER DEFAULT 40)
IS .....
Which one of the following will invoke the procedure correctly?

defproc(40, 70); (*)

defproc(10 => A, 25 => C);

defproc(30, 60 => C);

defproc(30 => A);

defproc;
Correct

Test: Section 8 Quiz

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 8 Quiz

(Answer all questions in this section)

6. Which of the following best describes how an input parameter affects a


Mark for Review
procedure?
(1) Points

It describes the order in which the procedure's statements should be


executed.

It allows complex calculations to be executed inside the procedure.

It describes which parts of the procedure's code are optional or


conditional.

It passes a value into the procedure when the procedure is invoked. (*)

It makes the procedure execute faster.

Correct

7. Which of the following statements about actual parameters is NOT true?


Mark for Review
(1) Points

An actual parameter can have a Boolean datatype.


The datatypes of an actual parameter and its formal parameter must be
compatible.

An actual parameter is declared in the calling environment, not in the


called procedure.

An actual parameter must be the name of a variable. (*)

An actual parameter can have a TIMESTAMP datatype.

Correct

8. You want to create a procedure which accepts a single parameter. The


Mark for Review
parameter is a number with a maximum value of 9999.99. Which of the
(1) Points
following is a valid declaration for this parameter?

(v_num NUMBER(4,2))

(v_num NUMBER) (*)

(v_num NUMBER(6,2))

(v_num)

Correct

9. A procedure has been created as:


Mark for Review
(1) Points
CREATE PROCEDURE myproc
(p_left NUMBER, p_right NUMBER)
IS BEGIN ....

You want to call the procedure from an anonymous block. Which of


the following calls is valid?

myproc(v_left, 30);

All of the above (*)


myproc(p_left, p_right);

myproc(v_left, v_right);

Correct

10.What is the correct syntax to create procedure MYPROC that accepts two
Mark for Review
number parameters X and Y?
(1) Points

CREATE PROCEDURE myproc (x NUMBER, y NUMBER) IS ... (*)

CREATE PROCEDURE (x NUMBER, y NUMBER) myproc IS ...

CREATE PROCEDURE IS myproc (x NUMBER, y NUMBER) …

CREATE PROCEDURE myproc IS (x NUMBER, y NUMBER) ...

Correct

You might also like