Вы находитесь на странице: 1из 161

Section 1 Quiz

(Answer all questions in this section)

1. Which of the following statements about PL/SQL and SQL is true?


Mark for Review
(1) Points

PL/SQL and SQL are both Oracle proprietary programming languages.


PL/SQL and SQL are both ANSI-compliant.
PL/SQL allows basic program logic and control flow to be combined with SQL
statements. (*)
PL/SQL and SQL can be used with many types of databases, including Oracle.

Incorrect. Refer to Section 1 Lesson 1.

2. Which of the following statements is true?


Mark for Review
(1) Points

(Choose all correct answers)

PL/SQL is an ANSI-compliant, procedural programming language.


SQL is an ANSI-compliant, nonprocedural, fourth-generation programming
language. (*)
PL/SQL is an Oracle proprietary, procedural, third-generation programming
language. (*)
PL/SQL is an Oracle proprietary, procedural, fourth-generation programming
language.

Incorrect. Refer to Section 1 Lesson 1.

3. Which of the following statements is true?


Mark for Review
(1) Points

You can embed PL/SQL statements within SQL code.


None of these are correct.
You can embed procedural constructs within SQL code.
You can embed SQL statements within PL/SQL code. (*)

Incorrect. Refer to Section 1 Lesson 1.

4. SQL is a common access language for many types of databases, including Oracle. True
or False? Mark for Review
(1) Points

True (*)
False

Correct

5. Nonprocedural languages allow the programmer to produce a result when a series of


steps are followed. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 1 Lesson 1.


6. Comparing
PL/SQL Mark for Review
with other (1) Points
languages
such as C
and Java,
which of
the
following
statements
is true?

PL/SQL is harder to learn


PL/SQL is easier to learn and more efficient (*)
PL/SQL is easier to learn but less efficient
PL/SQL is easier to learn and does not require an Oracle database or tool

Incorrect. Refer to Section 1 Lesson 2.

7. The fact that PL/SQL is portable is a good thing because:


Mark for Review
(1) Points

Exceptions can be ported to different operating systems


Blocks can be sent to the operating system.
PL/SQL code can be run on any operating system without a database
PL/SQL code can be developed on one platform and deployed on another
(*)

Incorrect. Refer to Section 1 Lesson 2.

8. PL/SQL differs from C and Java in which of the following ways? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)

It is the most complex programming language to learn.


It is the most efficient language to use with an Oracle database. (*)
It is not portable to other operating systems.
It does not support object-oriented programming.
It requires an Oracle database or tool. (*)

Incorrect. Refer to Section 1 Lesson 2.

9. Procedural constructs give you better control of your SQL statements and their
execution. True or False? Mark for Review
(1) Points

True (*)
False

Correct

10. When multiple SQL statements are combined into PL/SQL blocks, performance
will typically improve. True or False? Mark for Review
(1) Points

True (*)
False

11. Which
sections Mark for Review
of a (1) Points
PL/SQL
block are
optional?

Declaration and Exception (*)


Executable only
Declaration and Executable
Exception only

Correct

12. Which of the following tools can NOT be used to develop and test PL/SQL code?
Mark for Review
(1) Points
Oracle iSQL*Plus
Oracle JSQL (*)
Oracle Application Express
Oracle Jdeveloper

Incorrect. Refer to Section 1 Lesson 3.

13. Which lines of code will correctly display the message "The cat sat on the mat"?
(Choose two.) Mark for Review
(1) Points

(Choose all correct answers)

DBMS_OUTPUT.PUT_LINE('The cat' || 'sat on the mat');


DBMS_OUTPUT.PUT_LINE(The cat sat on the mat);
DBMS_OUTPUT.PUT_LINE('The cat sat ' || 'on the mat'); (*)
DBMS_OUTPUT.PUT_LINE('The cat sat on the mat'); (*)

Incorrect. Refer to Section 1 Lesson 3.

14. Every PL/SQL anonymous block must start with the keyword DECLARE. True or
False? Mark for Review
(1) Points

TRUE
FALSE (*)

Incorrect. Refer to Section 1 Lesson 3.

15. In a PL/SQL block, which of the following should not be followed by a


semicolon? Mark for Review
(1) Points

All SQL statements


END
DECLARE (*)
All PL/SQL statements

Incorrect. Refer to Section 1 Lesson 3.


1. You can
create a Mark for Review
Web site (1) Points
application
written
entirely in
PL/SQL.
True or
False?

True
False (*)

Incorrect. Refer to Section 1 Lesson 2.

2. Which of the following can be compiled as a standalone program outside the


database? Mark for Review
(1) Points

A program developed in PL/SQL or Java


None of these can be compiled outside of a database
A program developed in PL/SQL or C
Programs developed in Java or C, but not in PL/SQL (*)
A program developed in PL/SQL

Incorrect. Refer to Section 1 Lesson 2.

3. When multiple SQL statements are combined into PL/SQL blocks, performance
will typically improve. True or False? Mark for Review
(1) Points

True (*)
False

Correct

4. Which of the following can be done using PL/SQL?


Mark for Review
(1) Points

Manage database security


Update data (DML)
Develop Web applications using the Web Application Toolkit
Create customized reports
All of these can be done (*)

Incorrect. Refer to Section 1 Lesson 2.


5. Which of the following statements about exception handling in PL/SQL is false?
Mark for Review
(1) Points

Exception handling code tells your program what to do when an error is


encountered.
You can prepare for database exceptions by creating exception handlers.
None of these are false (*)
All of these are false
You can prepare for application exceptions by creating exception handlers.

Incorrect. Refer to Section 1 Lesson 2.


6. Which of
the Mark for Review
following (1) Points
statements
about
PL/SQL
and SQL is
true?

PL/SQL and SQL are both Oracle proprietary programming languages.


PL/SQL and SQL can be used with many types of databases, including
Oracle.
PL/SQL allows basic program logic and control flow to be combined with
SQL statements. (*)
PL/SQL and SQL are both ANSI-compliant.

Incorrect. Refer to Section 1 Lesson 1.

7. Fourth-generation programming languages include all except _____ and _____.


Mark for Review
(1) Points

(Choose all correct answers)

C++ (*)
Java (*)
MySQL
PL/SQL (*)
SQL

Incorrect. Refer to Section 1 Lesson 1.

8. Third-generation programming languages include all except _____ and _____.


Mark for Review
(1) Points
(Choose all correct answers)

SQL (*)
MySQL (*)
PL/SQL
C++
Java

Incorrect. Refer to Section 1 Lesson 1.

9. A program which specifies a list of operations to be performed sequentially to


achieve the desired result can be called: Mark for Review
(1) Points

Declarative
Nondeclarative
procedural (*)
low level

Incorrect. Refer to Section 1 Lesson 1.

10. PL/SQL is an Oracle proprietary, procedural, fourth-generation programming


language. True or False? Mark for Review
(1) Points

True
False (*)

Correct

11.Errors
are Mark for Review
handled (1) Points
in the
Exception
part of
the
PL/SQL
block.
True or
False?

True (*)
False

Correct

12. Which statements are mandatory in a PL/SQL block? (Choose two.)


Mark for
Review
(1) Points

(Choose all correct answers)

BEGIN (*)
EXCEPTION
DECLARE
END; (*)

Correct

13. In a PL/SQL block, which of the following should not be followed by a semicolon?
Mark for
Review
(1) Points

DECLARE (*)
All SQL statements
All PL/SQL statements
END

Correct

14. Which of the following is a PL/SQL programming environment?


Mark for
Review
(1) Points

Oracle Cdeveloper
PL/SQL Express
Java*Plus
SQL*Workshop in Application Express (*)

Incorrect. Refer to Section 1 Lesson 3.


15. Which keywords must be included in every PL/SQL block? (Choose two.)
Mark for
Review
(1) Points

(Choose all correct answers)

EXCEPTION
DECLARE
END; (*)
DBMS_OUTPUT.PUT_LINE
BEGIN (*)
Section 2 Quiz
(Answer all questions in this section)

1. Which of the following variable declarations does NOT use a number data type?
Mark for
Review
(1) Points

v_count PLS_INTEGER := 0;
v_students LONG; (*)
v_median_age NUMBER(6,2);
v_count BINARY_INTEGER;

Incorrect. Refer to Section 2 Lesson 4.

2. When declared using %TYPE, a variable will inherit ____ from the column on which it is
based. Mark for
Review
(1) Points

The data type and size of the column (*)


The name of the column
The value of the column

Correct

3. Delimiters are _____ that have special meaning to the Oracle database.
Mark for
Review
(1) Points

Identifiers
Variables
symbols (*)

Incorrect. Refer to Section 2 Lesson 2.

4. What is a
1. Which Mark for
statement Mark for Review
s about Review (1) Points
lexical
(1) Points
units are
true?
(Choose
two.)

(Choose all correct answers)

They are optional but can make a PL/SQL block


execute faster
They are named objects stored in the database
They are sequences of characters including
letters, digits, tabs, returns and symbols (*)
They are the building blocks of every PL/SQL
program (*)

Incorrect. Refer to Section 2


Lesson 2.

2. Which of the following are valid identifiers? (Choose


two.) Mark for
Review
(1) Points

(Choose all correct answers)

number_of_students_in_the_class
yesterday (*)
v$testresult (*)
#students
yesterday's date

Incorrect. Refer to Section 2


Lesson 2.

3. Examine the following code:


Mark for
DECLARE Review
x VARCHAR2(20); (1) Points
BEGIN
x:= 5 + 4 * 5 ;
DBMS_OUTPUT.PUT_LINE(x);
END;

What value of x will be displayed?

45
29
25 (*)
14

Correct

4. If today's date is 14th June 2007, which statement will


correctly convert today's date to the value: June 14, Mark for
2007 ? Review
(1) Points

TO_CHAR(sysdate, 'Month DD, YYYY') (*)


TO_CHAR(sysdate)
TO_DATE(sysdate,'Month DD, YYYY')
TO_DATE(sysdate)

Correct

5. PL/SQL statements must be written on a single line.


Mark for
Review
(1) Points

True
False (*)

Correct
unit?

A type of variable
A building block of a PL/SQL block (*)
A data type for a column

Incorrect. Refer to Section 2 Lesson 2.


5. Which of the following are valid PL/SQL operators? (Choose three.)
Mark for
Review
(1) Points

(Choose all correct answers)

Exception
Arithmetic (*)
Concatenation (*)
Exponential (*)

Incorrect. Refer to Section 2 Lesson 5.

6. The implicit
data type Mark for Review
conversion at (1) Points
Point A may
not work
correctly. Why
not?

DECLARE
v_mydate
DATE;
BEGIN
V_MYDATE
:= '29-Feb-
2004'; -- Point
A
END;

Oracle cannot implicitly convert a character string to a date, even if the


string contains a valid date value (*)
V_MYDATE has been entered in uppercase
There are only 28 days in February
If the database language is not English, 'Feb' has no meaning.

Correct

7. Which of the following data type conversions can be done implicitly?


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

(Choose all correct answers)

NUMBER to PLS_INTEGER (*)


DATE to NUMBER
NUMBER to VARCHAR2 (*)

Incorrect. Refer to Section 2 Lesson 5.

8. Which of the following are examples of good programming practice?


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

(Choose all correct answers)

Develop naming conventions for identifiers and other objects. (*)


Use implicit data type conversions.
Indent code so that it can be read more easily. (*)
Use table column names as the names of variables.
Document code with comments. (*)

Incorrect. Refer to Section 2 Lesson 7.

9. Comments change how a PL/SQL program executes, so an unsuitable


comment can cause the program to fail. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 2 Lesson 7.

10. If a variable is defined with the same name in both an inner and outer
block, and referenced in the outer block, it will reference the ___________ Mark for Review
block value of the variable. (1) Points

Neither - can't define a variable with the same name in both blocks
Inner
Outer (*)

Incorrect. Refer to Section 2 Lesson 6.

11. What will be displayed when the


following code is executed? Mark for Review
(1) Points
DECLARE
varA NUMBER := 12;
BEGIN
DECLARE
varB NUMBER := 8;
BEGIN
varA := varA + varB;
END;
DBMS_OUTPUT.PUT_LINE(varB);
END;

8
12
VarB
Nothing, the block will fail with
an error (*)
20

Incorrect. Refer to Section 2


Lesson 6.

12. Examine the following variable


declarations: Mark for Review
(1) Points
DECLARE
v_number NUMBER := 10;
v_result NUMBER;

Which of the following correctly


assigns the value 50 to V_RESULT?

All of these are correct (*)


v_result := v_number * 5;
v_result := 100 / 2;
v_result := ROUND(49.77);

Correct

13. After they are declared, variables


can be used only once in an Mark for Review
application. True or False? (1) Points

True
False (*)

Incorrect. Refer to Section 2


Lesson 1.
14. What are the data types of the
variables in the following Mark for Review
declaration? (1) Points

DECLARE
fname VARCHAR2(25);
lname VARCHAR2(25) DEFAULT
'fernandez';
BEGIN

PLS_INTEGER
Scalar (*)
Composite
LOB

Incorrect. Refer to Section 2


Lesson 3.

15. What is the data type of the variable


V_DEPT_TABLE in the following Mark for Review
declaration? (1) Points

DECLARE
TYPE dept_table_type IS
TABLE OF departments%ROWTYPE
INDEX BY PLS_INTEGER;
v_dept_table dept_table_type;

Composite (*)
PLS_INTEGER
Scalar
LOB

Correct
6. Is the
following Mark for Review
variable (1) Points
declaration
correct or
not?

DECLARE
test
NUMBER(5);

Correct. (*)
Not correct.
Correct

7. When a variable is defined using the NOT NULL keywords, the variable must
contain a value. True or False? Mark for Review
(1) Points

True (*)
False

Correct

8. Which of the following is a composite data type?


Mark for Review
(1) Points

RECORD (*)
VARCHAR2
CLOB
DATE

Correct

9. _____ are meant to store large amounts of data.


Mark for Review
(1) Points

LOBs (*)
VARCHAR2s
Scalar data types
Variables

Correct

10. What good programming practice would make this code easier to follow?
Mark for Review
DECLARE (1) Points
v_myvar VARCHAR2(20);
BEGIN
DECLARE
v_myvar VARCHAR2(15);
BEGIN
...
END;
END;
Labeling the blocks (*)
Developing a case convention for the code
Using a consistent naming convention for variables
Avoid using column names as identifiers

Correct
11. Which of
the Mark for Review
following (1) Points
will help
to make
code
easier to
read?

Naming variables.
Using %Type.
Including comments in the code. (*)

Incorrect. Refer to Section 2 Lesson 7.

12. Examine the following code. At Line A, we want to assign a value of 22 to the
outer block's variable v_myvar. What code should we write at Line A? Mark for Review
(1) Points
<< outer_block >>
DECLARE
v_myvar NUMBER;
BEGIN
<< inner_block >>
DECLARE
v_myvar NUMBER := 15;
BEGIN
-- Line A
END;
END;

We cannot reference the outer block's variable because both variables


have the same name
<< outer_block>>.v_myvar := 22
outer_block.v_myvar := 22; (*)
v_myvar := 22;
v_myvar(outer_block) := 22;

Incorrect. Refer to Section 2 Lesson 6.

13. What will be displayed when the following code is executed?


Mark for Review
(1) Points
DECLARE
varA NUMBER := 12;
BEGIN
DECLARE
varB NUMBER := 8;
BEGIN
varA := varA + varB;
END;
DBMS_OUTPUT.PUT_LINE(varB);
END;

Nothing, the block will fail with an error (*)


VarB
12
8
20

Correct

14. Code is easier to read if you declare one identifier per line. True or False?
Mark for Review
(1) Points

True (*)
False

Correct

15. You need to declare a variable to hold a value which has been read from the
SALARY column of the EMPLOYEES table. Which of the following is an Mark for Review
advantage of declaring the variable as: employees.salary%TYPE ? (1) Points

It is shorter than coding NUMBER(8,2)


If the SALARY column is ALTERed later, the PL/SQL code need not be
changed. (*)
It allows the software to perform implicit data type conversions.
It executes much faster than using NUMBER(8,2)

Incorrect. Refer to Section 2 Lesson 4.


Section 3 Quiz
(Answer all questions in this section)

1. Examine the following code: BEGIN


INSERT INTO animals VALUES ('aa','aardvarks'); Mark for Review
SAVEPOINT sp_1; (1) Points
INSERT INTO animals VALUES ('bb','big birds');
SAVEPOINT sp_2;
ROLLBACK TO sp_1;
INSERT INTO animals VALUES ('cc','cool cats');
COMMIT;
END;
Which row(s) will be in the ANIMALS table after this block is executed?

aardvaarks, big birds and cool cats


cool cats
aardvaarks and cool cats (*)
big birds and cool cats

Incorrect. Refer to Section 3 Lesson 4.

2. In a PL/SQL block, where can you code a COMMIT statement?


Mark for Review
(1) Points

Only the Executable section.


Nowhere; the COMMIT statement must be outside the block.
In any section of the block: Declaration, Executable, or Exception.
In the Executable and/or the Exception sections. (*)

Incorrect. Refer to Section 3 Lesson 4.

3. Which of the following use an implicit cursor?


Mark for Review
(1) Points

DML statements only.


COMMIT and ROLLBACK statements only.
DML statements and SELECT statements which return a single row. (*)
SELECT statements only.

Incorrect. Refer to Section 3 Lesson 3.

4. There are three employees in department 90. What will be displayed when the
following code is executed? Mark for Review
(1) Points
DECLARE
v_open CHAR(3) := 'NO';
BEGIN
UPDATE employees
SET job_id = 'ST_CLERK'
WHERE department_id = 90;
IF SQL%FOUND THEN
v_open := 'YES';
END IF;
DBMS_OUTPUT.PUT_LINE(v_open || ' ' || SQL%ROWCOUNT);
END;

YES 1
Nothing will be displayed. The block will fail because you cannot use implicit
cursor attributes directly in a call to DBMS_OUTPUT.PUT_LINE.
YES 3 (*)
NO 3

Incorrect. Refer to Section 3 Lesson 3.

5. Which of the following SQL DML commands can be used inside a PL/SQL block?
Mark for Review
(1) Points

INSERT, UPDATE, and DELETE only.


UPDATE and DELETE only.
INSERT, UPDATE, DELETE, and MERGE. (*)
INSERT and UPDATE only.

Incorrect. Refer to Section 3 Lesson 3.


6. A variable is declared as:
Mark for Review
DECLARE (1) Points
v_salary
employees.salary%TYPE;
BEGIN

Which of the following is a


correct use of the INTO
clause?

SELECT salary
FROM employees
INTO v_salary;
SELECT salary
INTO v_salary
FROM employees
WHERE employee_id=100;

(*)
SELECT salary
FROM employees
WHERE employee_id=100
INTO v_salary;
SELECT v_salary
INTO salary
FROM employees
WHERE employee_id=100;
Incorrect. Refer to Section 3 Lesson
2.

7. The following code will return the last name of the employee
whose employee id is equal to 100: True or False? Mark for Review
(1) Points
DECLARE
v_last_name employees.last_name%TYPE;
employee_id employees.employee_id%TYPE := 100;
BEGIN
SELECT last_name INTO v_last_name
FROM employees
WHERE employee_id = employee_id;
END;

True
False (*)

Incorrect. Refer to Section 3 Lesson


2.

8. What will happen when the following block is executed?


Mark for Review
DECLARE (1) Points
v_last employees.last_name%TYPE;
v_first employees.first_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
SELECT first_name, last_name
INTO v_first, v_last, v_salary
FROM employees WHERE employee_id=100;
END

The block will execute successfully, and the V_SALARY


variable will be set to NULL.
The block will fail because the SELECT is trying to read two
columns into three PL/SQL variables. (*)
The block will fail because V_LAST was declared before
V_FIRST.
The block will fail because the SELECT statement returns
more than one row.

Incorrect. Refer to Section 3 Lesson


2.

9. Which of the following is NOT a good guideline for retrieving


data in PL/SQL? Mark for Review
(1) Points

Specify the same number of variables in the INTO clause


as database columns in the SELECT clause.
The WHERE clause is optional in nearly all cases. (*)
Declare the receiving variables using %TYPE
THE SELECT statement should fetch exactly one row.

Incorrect. Refer to Section 3 Lesson


2.

10. When used in a PL/SQL block, which SQL statement must return
exactly one row? Mark for Review
(1) Points

DELETE
SELECT (*)
INSERT
UPDATE
MERGE

Correct
11. The
UPDATE Mark for Review
statement (1) Points
can be
used to
update
more than
one row
at a time.
True or
False?

True (*)
False

Correct

12. To modify an existing row in a table, you can use the ________ statement.
Mark for Review
(1) Points

INSERT
ALTER
UPDATE (*)
MODIFY

Incorrect. Refer to Section 3 Lesson 1.


13. Which of the following will delete all employees who work in the Sales
department? Mark for Review
(1) Points

DELETE (SELECT department_id


FROM departments
WHERE department_name = 'Sales')
FROM employees;
DELETE FROM employees
WHERE department_id =
SELECT department_id
FROM departments
WHERE department_name = 'Sales';
DELETE FROM employees e, departments d
WHERE e.department_id = d.department_id
AND department_name = 'Sales';
DELETE FROM employees
WHERE department_id =
(SELECT department_id
FROM departments
WHERE department_name = 'Sales');

(*)

Incorrect. Refer to Section 3 Lesson 1.

14. You want to modify existing rows in a table. Which of the following are NOT
needed in your SQL statement? Mark for Review
(1) Points

The name of the table.


A new value for the column you want to modify (this can be an expression
or a subquery).
The name of the column(s) you want to modify.
A MODIFY clause. (*)
An UPDATE clause.

Incorrect. Refer to Section 3 Lesson 1.

15. When explicitly inserting a row into a table, the VALUES clause must include a
value for every column of the table. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 3 Lesson 1.


1. Which of
the Mark for Review
following (1) Points
is NOT a
good
guideline
for
retrieving
data in
PL/SQL?

Specify the same number of variables in the INTO clause as database


columns in the SELECT clause.
The WHERE clause is optional in nearly all cases. (*)
THE SELECT statement should fetch exactly one row.
Declare the receiving variables using %TYPE

Incorrect. Refer to Section 3 Lesson 2.

2. A variable is declared as:


Mark for Review
DECLARE (1) Points
v_holdit employees.last_name%TYPE;
BEGIN ...

Which of the following is a correct use of the INTO clause?

SELECT last_name
INTO v_holdit
FROM employees;
SELECT salary
INTO v_holdit
FROM employees
WHERE employee_id=100;
SELECT last_name
INTO v_holdit
FROM employees
WHERE employee_id=100;

(*)
SELECT *
INTO v_holdit
FROM employees;

Incorrect. Refer to Section 3 Lesson 2.

3. Which rows will be deleted from the EMPLOYEES table when the following code is
executed? Mark for Review
(1) Points
DECLARE
salary employees.salary%TYPE := 12000;
BEGIN
DELETE FROM employees
WHERE salary > salary;
END;

All rows whose SALARY column value is equal to 12000.


No rows. (*)
All rows in the table.
All rows whose SALARY column value is greater than 12000.

Incorrect. Refer to Section 3 Lesson 2.

4. Which one of these SQL statements can be directly included in a PL/SQL


executable block? Mark for Review
(1) Points

SHOW USER;
SELECT * FROM DUAL;
IF... THEN...;
INSERT INTO...; (*)

Incorrect. Refer to Section 3 Lesson 2.

5. Look at this PL/SQL block:


Mark for Review
DECLARE (1) Points
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM employees WHERE salary > 50000;
END;

No employees earn more than $50000. Which of the following statements are
true? (Choose two).

(Choose all correct answers)

The SELECT will return value 0 into V_COUNT. (*)


The SELECT returns exactly one row. (*)
The SELECT will fail because it does NOT return exactly one row.
The block will fail because no results are displayed to the user.
The block will fail because variable V_SALARY was not declared.

Correct
6. The
MERGE Mark for Review
statement (1) Points
will
INSERT
or
DELETE
rows in a
target
table
based on
matching
values in
a source
table.
True or
False?

True
False (*)

Incorrect. Refer to Section 3 Lesson 1.

7. Is it possible to insert more than one row at a time using an INSERT statement
with a VALUES clause? Mark for Review
(1) Points

No, you can only create one row at a time when using the VALUES clause.
(*)
No, there is no such thing as INSERT ... VALUES.
Yes, you can list as many rows as you want, just remember to separate the
rows with commas.

Correct

8. If a DELETE statement does not include a WHERE clause, all rows in the table
are deleted. True or False? Mark for Review
(1) Points

True (*)
False

Correct

9. What will happen when the following statement is executed?


Mark for Review
UPDATE employees (1) Points
SET salary = 5000, commission_pct = NULL WHERE department_id = 50; ;

Assume there are no integrity constraint issues.

The statement fails because you cannot use NULL in the SET clause.
The statement fails because you cannot modify more than one column in a
single UPDATE statement.
All employees in department 50 have their salary changed to 5000 and their
commission percentage set to NULL. (*)
All employees who have a salary of 5000 have their commission percentage
set to NULL.

Incorrect. Refer to Section 3 Lesson 1.

10. The following table has been created:


Mark for Review
CREATE TABLE student_table (1) Points
(stud_id NUMBER(6),
last_name VARCHAR2(20),
first_name VARCHAR2(20),
lunch_num NUMBER(4));
Which one of the following INSERT statements will fail?

INSERT INTO student_table


VALUES (143354, 'Roberts', 'Cameron', 6543);
INSERT INTO student_table (stud_id, last_name, first_name, lunch_num)
VALUES (143354, 'Roberts', 'Cameron', 6543);
INSERT INTO student_table (stud_id, last_name, lunch_num)
VALUES (143354, 'Roberts', 6543, 'Cameron');

(*)
INSERT INTO student_table (stud_id, lunch_num, first_name, last_name)
VALUES (143352, 6543, 'Cameron', 'Roberts');

Incorrect. Refer to Section 3 Lesson 1.


11. A PL/SQL
block Mark for Review
contains the (1) Points
following
DML
statement:

UPDATE
wf_countries
SET
population =
population *
1.1
WHERE
country_id =
229;

Which kind of
cursor is
used for this
statement?

An explicit cursor which must be declared and named by the PL/SQL


programmer.
An explicit cursor named "SQL".
An implicit cursor named "SQL". (*)
An implicit cursor named "WF_COUNTRIES".

Incorrect. Refer to Section 3 Lesson 3.

12. There are no employees in Department 77. What will happen when the
following block is executed? Mark for Review
BEGIN (1) Points
DELETE FROM employees
WHERE department_id=77;

DBMS_OUTPUT.PUT_LINE(SQL%ROWCOUNT)
END;

A zero (0) is displayed. (*)


A NO_DATA_FOUND exception is raised.
An exception is raised because the block does not contain a COMMIT
statement.
A NULL is displayed.

Correct

13. A PL/SQL block includes the following statement:


Mark for Review
SELECT last_name INTO v_last_name (1) Points
FROM employees
WHERE employee_id=100;

What is the value of SQL%FOUND immediately after the SELECT statement


is executed?

False
True (*)
Null
Error. That attribute does not apply for implicit cursors.

Incorrect. Refer to Section 3 Lesson 3.

14. How many transactions are in the following block?


Mark for Review
BEGIN (1) Points
INSERT INTO countries (country_id, country_name)
VALUES ('XA', 'Xanadu');
INSERT INTO countries (country_id, country_name)
VALUES ('NV', 'Neverland');
UPDATE countries
SET country_name='Deutchland'
WHERE country_id='DE';
UPDATE countries
SET region_id=1
WHERE country_name LIKE '%stan';
END;

How many transactions are shown above?

Four; each DML is a separate transaction


It depends on how many rows are updated - there will be a separate
transaction for each row.
One (*)
Two; both the INSERTs are one transaction and both the UPDATEs are
a second transaction.

Incorrect. Refer to Section 3 Lesson 4.

15. How many DML statements can be included in a single transaction?


Mark for Review
(1) Points

None. A transaction cannot include DML statements.


A maximum of four DML statements
As many as needed (*)
Only one

Incorrect. Refer to Section 3 Lesson 4.

Section 4 Quiz
(Answer all questions in this section)

1. Which one of these tasks is best done using a LOOP statement?


Mark for Review
(1) Points

Calculating and displaying the sum of all integers from 1 to 100 (*)
Assigning a letter grade to a numerical score
Testing if a condition is true, false, or null
Fetching and displaying an employee's last name from the database

Correct

2. Look at this code:


Mark for Review
DECLARE (1) Points
v_bool BOOLEAN := TRUE;
v_date DATE;
BEGIN
LOOP
EXIT WHEN v_bool;
SELECT SYSDATE INTO v_date FROM dual;
END LOOP;
END;

How many times will the SELECT statement execute?

Never (the SELECT will not execute at all) (*)


Twice
An infinite number of times because the EXIT condition will never be true
Once

Correct

3. Which kind of loop is this?


Mark for Review
i := 10; (1) Points
LOOP
i := i + 1;
EXIT WHEN i > 30;
END LOOP;

A nested loop
A WHILE loop
A FOR loop
A basic loop (*)
An infinite loop

Incorrect. Refer to Section 4 Lesson 3.

4. Which statement best describes when a FOR loop should be used?


Mark for Review
(1) Points

When we want to exit from the loop when a Boolean variable becomes FALSE.
When an implicitly declared counter must increase by 1 in each iteration of the
loop. (*)
When the statements inside the loop must execute at least once.
When an EXIT WHEN statement must be coded.

Incorrect. Refer to Section 4 Lesson 4.


5. You want a loop that counts backwards from 10 through 1. How do you code that?
Mark for Review
(1) Points

FOR i IN 1 .. 10 BY -1 LOOP
FOR i IN REVERSE 10 .. 1 LOOP
FOR i IN REVERSE 1 .. 10 LOOP (*)
FOR i IN 10 .. 1 LOOP

Incorrect. Refer to Section 4 Lesson 4.

6. What will happen when the


following code is executed? Mark for Review
(1) Points
BEGIN
FOR i in 1 ..3 LOOP
DBMS_OUTPUT.PUT_LINE
(i);
i := i + 1;
END LOOP;
END;

It will result in an error because you cannot modify the


counter in a FOR loop. (*)
It will result in an error because the counter was not
explicitly declared.
It will display 1, 2, 3.
It will display 2, 3, 4.

Correct

7. What will be the value of variable c after the following code is


executed? Mark for Review
(1) Points
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := NULL;
c NUMBER;
BEGIN
IF a AND b THEN c := 2;
ELSIF a OR b THEN c := 0;
ELSE c := 1;
END IF;
END;

2
Null
0 (*)
1

Incorrect. Refer to Section 4


Lesson 2.

8. What will be the value of v_sal_desc after the following code


is executed? Mark for Review
(1) Points
DECLARE
v_salary NUMBER(6,2) := NULL;
v_sal_desc VARCHAR2(10);
BEGIN
CASE
WHEN v_salary < 10000 THEN v_sal_desc := 'Low
Paid';
WHEN v_salary >= 10000 THEN v_sal_desc := 'High
Paid';
END CASE;
END;

High Paid
The code will fail and return an unhandled exception
error to the host environment (*)
Low Paid
Null

Incorrect. Refer to Section 4


Lesson 2.

9. How must you end a CASE expression?


Mark for Review
(1) Points

END CASE;
ENDCASE;
END; (*)
ENDIF;

Incorrect. Refer to Section 4


Lesson 2.

10. In the following code fragment, you want to exit from the
outer loop at Line A if v_number = 6. Which statement would Mark for Review
you write on Line A? (1) Points

<< big_loop >>


WHILE condition_1 LOOP
<< small_loop >>
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE(i);
-- Line A
END LOOP;
END LOOP;

EXIT outer_loop WHEN v_number = 6;


IF v_number = 6 THEN EXIT;
EXIT small_loop WHEN v_number = 6;
EXIT big_loop WHEN v_number = 6; (*)

Incorrect. Refer to Section 4


Lesson 5.
11. What
kinds Mark for Review
of (1) Points
loops
can be
nested?

FOR loops
All of these. (*)
BASIC loops
WHILE loops

Incorrect. Refer to Section 4 Lesson 5.

12. …BEGIN
<< Outer_loop >> Mark for Review
LOOP v_counter := v_counter+1; (1) Points
EXIT WHEN v_counter>10;
<< Inner_loop >>
LOOP
...
EXIT Outer_loop WHEN v_total_done = 'YES';
-- Leave both loops
EXIT WHEN v_inner_done = 'YES';
-- Leave inner loop only
...
END LOOP Inner_loop;
...
END LOOP Outer_loop;
END;

In this code it is valid for each loop to have it's own EXIT statement. True or
False?

True (*)
False
Correct

13. Look at the following (badly written) code:


Mark for Review
age := 5; IF age<30 THEN mature := 'adult'; (1) Points
ELSIF age<22 THEN mature := 'teenager';
ELSIF age<13 THEN mature := 'child';
END IF;
DBMS_OUTPUT.PUT_LINE(mature);

What will be displayed when this code is executed?

Child
adult (*)
Adultteenagerchild
Teenager

Incorrect. Refer to Section 4 Lesson 1.

14. We want to execute one of three statements depending on whether the value in
V_VAR is 10, 20, or some other value. What should be coded at Line A? Mark for Review
(1) Points
IF v_var = 10 THEN
statement1;
-- Line A
statement2;
ELSE
statement3;
END IF;

IF v_var = 20 THEN
ELSIF v_var = 20
ELSIF v_var = 20 THEN (*)
ELSE IF v_var = 20 THEN

Incorrect. Refer to Section 4 Lesson 1.

15. You want to repeat a set of statements 100 times, incrementing a counter each
time. What kind of PL/SQL control structure would you use? Mark for Review
(1) Points

IF...THEN...ELSIF...ELSE
CASE...WHEN...THEN
A loop (*)
IF...THEN...ELSE
Incorrect. Refer to Section 4 Lesson 1.

1. You need to execute a set of


statements 10 times, increasing a Mark for Review
counter by 1 each time. Which of the (1) Points
following PL/SQL constructs can do
this? (Choose three)

(Choose all correct answers)

CASE ... WHEN ... THEN


A WHILE loop (*)
A basic loop (*)
IF ... THEN ... ELSE
A FOR loop (*)

Incorrect. Refer to Section 4


Lesson 1.

2. What will be displayed when this block


is executed? DECLARE Mark for Review
v_birthdate DATE; (1) Points
BEGIN
IF v_birthdate < '01-Jan-2000'
THEN
DBMS_OUTPUT.PUT_LINE(' Born in
the 20th century ');
ELSE
DBMS_OUTPUT.PUT_LINE(' Born in
the 21st century ');
END IF;
END;

Born in the 20th century


Exception raised because no date
given
Born in the 21st century (*)

Incorrect. Refer to Section 4


Lesson 1.

3. What will be displayed when this block


is executed? Mark for Review
(1) Points
DECLARE
v_bool1 BOOLEAN := NULL;
v_bool2 BOOLEAN := NULL;
v_char VARCHAR(10) := 'Start';
BEGIN
IF (v_bool1 = v_bool2) THEN
v_char:='Equal';
ELSE v_char:='Not equal';
END IF;
DBMS_OUTPUT.PUT_LINE(v_char);
END;

Nothing will be displayed. The


block will fail because you cannot
compare two null values.
Equal
Start
Not equal (*)

Incorrect. Refer to Section 4


Lesson 1.

4. How many EXIT statements can be


coded inside a basic loop? Mark for Review
(1) Points

One only
Two
As many as you need, there is no
limit (*)
None

Incorrect. Refer to Section 4


Lesson 3.

5. A PL/SQL block contains the following


code: Mark for Review
v_counter := 1; (1) Points
LOOP
EXIT WHEN v_counter=5;
END LOOP;
v_counter := v_counter + 1;

What is the value of V_COUNTER after


the loop is finished?

1
5
6
This is an infinite loop; the loop
will never finish. (*)

Incorrect. Refer to Section 4


Lesson 3.
6. Examine the following block:
Mark for Review
DECLARE (1) Points
v_counter PLS_INTEGER := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(v_counter);
v_counter := v_counter + 1;
EXIT WHEN v_counter = 5;
END LOOP;
END;

What is the last value of V_COUNTER that is


displayed?

6
4 (*)
5
This is an infinite loop; the loop will never
finish.

Incorrect. Refer to
Section 4 Lesson 3.

7. Examine the following code:


Mark for Review
DECLARE (1) Points
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
CASE v_score
-- Line A
....

The CASE statement must convert a numeric


score to a letter grade: 90 -> A, 80 -> B, 70 -
> C and so on.

What should be coded at Line A?

WHEN 90 THEN v_grade := 'A'; (*)


WHEN 90 THEN 'A';
WHEN 90 THEN 'A'
WHEN 90 THEN v_grade = 'A'

Correct

8. What will be the value of variable c after the


following code is executed? Mark for Review
(1) Points
DECLARE
a BOOLEAN := TRUE;
b BOOLEAN := FALSE;
c NUMBER;
BEGIN
c :=
CASE
WHEN a AND b THEN 10
WHEN NOT a THEN 20
WHEN a OR b THEN 30
ELSE 40
END CASE;
END;

10
30 (*)
40
20

Incorrect. Refer to
Section 4 Lesson 2.

9. Examine the following code:


Mark for Review
DECLARE (1) Points
v_score NUMBER(3);
v_grade CHAR(1);
BEGIN
v_grade := CASE v_score
-- Line A
....

The CASE expression must convert a numeric


score to a letter grade: 90 -> A, 80 -> B, 70 -
> C and so on. What should be coded at Line
A?

WHEN 90 THEN v_grade := 'A';


WHEN 90 THEN = 'A';
WHEN 90 THEN 'A' (*)
WHEN 90 THEN grade := 'A'

Incorrect. Refer to
Section 4 Lesson 2.

10. When the following code is executed, how


many lines of output will be displayed? Mark for Review
(1) Points
BEGIN
FOR i IN 1..5 LOOP
FOR j IN 1..8 LOOP
DBMS_OUTPUT.PUT_LINE(i || ',' || j);
END LOOP;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;

41
45 (*)
14
80

Incorrect. Refer to
Section 4 Lesson 5.

11. What clause will leave the outer


loop at Point A? Mark for Review
(1) Points
DECLARE
i INTEGER := 0;
BEGIN
<< i_loop >>
WHILE i <= 10 LOOP
i := i+1;
<< j_loop >>
FOR j IN 1..5 LOOP
_______ WHEN i = j*2; --
Point A
DBMS_OUTPUT.PUT_LINE(i
|| j);
END LOOP;
END LOOP;
END;

EXIT outerloop
EXIT i_loop (*)
EXIT j_loop
EXIT << outerloop>>

Incorrect. Refer to Section 4


Lesson 5.

12. What statement allows you to exit the inner loop at Point
A in the following block? Mark for Review
(1) Points
DECLARE
v_outer_done CHAR(3) := 'NO';
v_inner_done CHAR(3) := 'NO';
BEGIN
LOOP -- outer loop
...
LOOP -- inner loop
...
v_inner_done := "YES";
... -- Point A
...
END LOOP;
...
EXIT;
...
END LOOP;
END;

EXIT << inner loop>>


EXIT WHEN v_inner_done = 'YES'; (*)
EXIT AT v_inner_done = 'YES';
WHEN v_inner_done = YES EXIT;

Incorrect. Refer to Section 4


Lesson 5.

13. In a WHILE loop, the statements inside the loop must


execute at least once. True or False? Mark for Review
(1) Points

TRUE
FALSE (*)

Incorrect. Refer to Section 4


Lesson 4.

14. In a FOR loop, an implicitly declared counter


automatically increases or decreases with each iteration. Mark for Review
True or False? (1) Points

TRUE (*)
FALSE

Correct

15. When using a counter to control a FOR loop, which of the


following is true ? Mark for Review
(1) Points

You must have exactly one counter but it is implicitly


declared. (*)
You don't need a counter; you can test for anything
(for example, whether a BOOLEAN is TRUE or
FALSE).
You can have multiple counters, but you need at
least one.
You must have exactly one counter and you must
explicitly declare it.

Correct

Section 5 Quiz
(Answer all questions in this section)

1. Consider the following code:


Mark for Review
DECLARE (1) Points
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?

two
one
four (*)
three

Incorrect. Refer to Section 5 Lesson 1.

2. You can store a whole record in a single variable using %ROWTYPE or by creating your
own record structure as a type and then declaring a variable of that type. Mark for Review
(1) Points

True (*)
False

Correct

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


Mark for Review
(1) Points

True (*)
False

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

True (*)
False

Correct

5. Consider the following code:


Mark for Review
DECLARE (1) Points
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_dept_info_rec dept_info_type;
v_emp_dept_rec emp_dept_type;

How many fields can be addressed in v_dept_info_rec?

two (*)
Four
One
Three

Correct

6. Which of
these Mark for Review
PL/SQL (1) Points
data
structures
can NOT
store a
collection?

An INDEX BY table indexed by BINARY_INTEGER


An INDEX BY table indexed by PLS_INTEGER
A PL/SQL record (*)
An INDEX BY table of records

Incorrect. Refer to Section 5 Lesson 2.

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


Mark for Review
(1) Points

True (*)
False

Correct

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


Mark for Review
(1) Points

Either one. (*)


%ROWTYPE
a user-defined record

Correct

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

True (*)
False

Correct

10. 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? Mark for Review
(1) Points

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 TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;

(*)
DECLARE
TYPE t_depttab IS INDEX BY TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;

Incorrect. Refer to Section 5 Lesson 2.

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

True
False (*)

Incorrect. Refer to Section 5 Lesson 2.

12. What is the largest number of elements (i.e., records) that an INDEX BY table of
records can contain? Mark for Review
(1) Points

32767
100
None of these.
Many millions of records because a BINARY_INTEGER or PLS_INTEGER can
have a very large value (*)
4096

Incorrect. Refer to Section 5 Lesson 2.

13. 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)

DROP
COUNT (*)
EXISTS (*)
FIRST (*)
PREVIOUS
Incorrect. Refer to Section 5 Lesson 2.

14. Which of these PL/SQL data structures could store a complete copy of the
employees table, i.e., 20 complete table rows? Mark for Review
(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 5 Lesson 2.

15. 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

1. Consider the following code:


Mark for Review
DECLARE (1) Points
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?
four (*)
three
two
one

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

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 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 defined as NOT NULL.
It must contain one or more
components, but all the
components must have scalar
datatypes. (*)

Incorrect. Refer to Section 5


Lesson 1.

5. You can store a whole record in a single


variable using %ROWTYPE or by Mark for Review
creating your own record structure as a (1) Points
type and then declaring a variable of
that type.

True (*)
False

Correct

6. Which of
these Mark for Review
PL/SQL (1) Points
data
structures
can NOT
store a
collection?

An INDEX BY table indexed by PLS_INTEGER


An INDEX BY table of records
A PL/SQL record (*)
An INDEX BY table indexed by BINARY_INTEGER

Incorrect. Refer to Section 5 Lesson 2.

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

An INDEX BY table of records (*)


An INDEX BY table
An explicit cursor based on SELECT * FROM employees;
A record

Correct

8. 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 (*)
DROP
PREVIOUS
FIRST (*)
COUNT (*)

Incorrect. Refer to Section 5 Lesson 2.

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

True (*)
False

Correct

10. 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? Mark for Review
(1) Points

DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEXED BY NUMBER;
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%TYPE
INDEX BY BINARY_INTEGER;
Incorrect. Refer to Section 5 Lesson 2.

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

True
False (*)

Incorrect. Refer to Section 5 Lesson 2.

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


Mark for Review
(1) Points

%ROWTYPE
a user-defined record
Either one. (*)

Incorrect. Refer to Section 5 Lesson 2.

13. What is the largest number of elements (i.e., records) that an INDEX BY table of
records can contain? Mark for Review
(1) Points

None of these.
4096
Many millions of records because a BINARY_INTEGER or PLS_INTEGER can
have a very large value (*)
32767
100

Correct

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


Mark for Review
(1) Points

True (*)
False

Correct

15. Identify the valid collection types:


Mark for Review
(1) Points

(Choose all correct answers)

INDEX BY TABLE (*)


INDEX BY TABLE OF ROWS
INDEX BY TABLE OF RECORDS (*)
INDEX BY VIEW

Incorrect. Refer to Section 5 Lesson 2.

Section 6 Quiz
(Answer all questions in this section)

1. What is wrong with the following code?


Mark for Review
BEGIN (1) Points
FOR emp_rec IN
(SELECT * FROM employees WHERE ROWNUM < 10 ) LOOP
DBMS_OUTPUT.PUT_LINE(emp_rec%ROWCOUNT || emp_rec.last_name):
END LOOP;
END;

You cannot use ROWNUM with a cursor FOR loop.


You cannot use FOR UPDATE NOWAIT with a cursor FOR loop using a subquery.
The cursor has not been opened.
The field EMP_REC.LAST_NAME does not exist.
You cannot reference %ROWCOUNT with a cursor FOR loop using a subquery. (*)

Incorrect. Refer to Section 6 Lesson 3.

2. Look at the following code:


Mark for Review
DECLARE (1) Points
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?

emp_cursor.salary
emp_record.salary (*)
employees.salary
emp_record.employees.salary
TO_CHAR(salary)

Incorrect. Refer to Section 6 Lesson 3.

3. When can we use the WHERE CURRENT OF clause?


Mark for Review
(1) Points

When the cursor has not been OPENed


Only with an UPDATE, but not with a DELETE
When the cursor is based on a single table (not on a join)
When the cursor is declared as SELECT ... FOR UPDATE ...; (*)
Only with a DELETE, but not with an UPDATE

Incorrect. Refer to Section 6 Lesson 5.

4. You have declared the following cursor: CURSOR country_curs IS


SELECT country_id, country_name Mark for Review
FROM wf_countries (1) Points
FOR UPDATE WAIT 10; Another user updates a row in WF_COUNTRIES but does not
COMMIT the update. What will happen when you OPEN country_curs; ?

The other user's transaction is automatically rolled back.


Your session waits for 10 seconds, and then returns control to your block so that it
can continue to execute. (*)
Your block fails because you should have coded: FOR UPDATE WAIT (10);
Your session waits indefinitely until the other user COMMITs.
A LOCKED_ROWS exception is raised immediately.

Incorrect. Refer to Section 6 Lesson 5.

5. You want to fetch rows from the EMPLOYEES table. You want to lock the fetched rows
to prevent other users from updating them. You declare the following cursor: CURSOR Mark for Review
emp_curs IS (1) Points
SELECT employee_id, last_name, salary
FROM employees
-- Line A -- ; What should you code at Line A?

FOR LOCK
FOR UPDATE OF employees
FOR UPDATE (*)
FOR UPDATE (employees)

Incorrect. Refer to Section 6 Lesson 5.

6. Examine the following code


fragment: Mark for Review
(1) Points
DECLARE
CURSOR emp_curs IS
SELECT first_name,
last_name FROM employees;
v_emp_rec
emp_curs%ROWTYPE;
BEGIN
...
FETCH emp_curs INTO
v_emp_rec;
DBMS_OUTPUT.PUT_LINE(..
Point A ...);
...

To display the fetched last


name, what should you code
at Point A?

v_emp_rec
v_emp_rec.last_name (*)
v_emp_rec(last_name)
None of these.
last_name

Incorrect. Refer to Section 6


Lesson 2.

7. The DEPARTMENTS table contains four columns. Examine


the following code: Mark for Review
(1) Points
DECLARE
CURSOR dept_curs IS
SELECT * FROM departments;
v_dept_rec dept_curs%ROWTYPE;
BEGIN
OPEN dept_curs;
FETCH dept_curs INTO v_dept_rec;
...

Which one of the following statements is true?

The FETCH will fail because the structure of


v_dept_rec does not match the structure of the cursor.
The block will fail because the declaration of
v_dept_rec is invalid.
v_dept_rec contains the first row of the departments
table. (*)
v_dept_rec contains the first four rows of the
departments table.

Incorrect. Refer to Section 6


Lesson 2.

8. What is one of the advantages of using parameters with a


cursor? Mark for Review
(1) Points

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 declare the cursor FOR UPDATE.
It will execute much faster than a cursor without
parameters.
You can use a cursor FOR loop.

Correct

9. A cursor has been declared as:


CURSOR c_curs (p_param VARCHAR2) IS Mark for Review
SELECT * FROM mytable (1) Points
WHERE mycolumn = p_param;
Which of the following will open the cursor successfully?

p_param := 'ABC';
OPEN c_curs(p_param);
OPEN c_curs(p_param = "ABC");
OPEN c_curs USING ("ABC");
OPEN c_curs('ABC'); (*)

Incorrect. Refer to Section 6


Lesson 4.

10. An explicit cursor must always be declared, opened, and


closed by the PL/SQL programmer. True or False? Mark for Review
(1) Points
TRUE
FALSE (*)

Incorrect. Refer to Section 6


Lesson 1.

11. Examine the following code:


Mark for
DECLARE Review
CURSOR emp_curs IS (1) Points
SELECT last_name,
salary
FROM employees
ORDER BY salary;
v_last_name
employees.last_name%TYPE;

v_salary
employees.salary%TYPE;
BEGIN
...
Which of the following
statements successfully
opens the cursor and fetches
the first row of the active
set?

OPEN emp_curs;
FETCH emp_curs;
OPEN emp_curs;
FETCH emp_curs INTO v_salary, v_last_name;
OPEN emp_curs;
FETCH emp_curs INTO v_last_name, v_salary;

(*)
OPEN emp_curs;
FETCH FIRST emp_curs INTO v_last_name, v_salary;

Incorrect. Refer to Section 6


Lesson 1.

12. For which type of SQL statement must you use an explicit
cursor? Mark for
Review
(1) Points

Queries that return more than one row (*)


Data Definition Language (DDL) statements
DML statements that process more than one row
Queries that return a single row

Correct

13. The employees table contains 20 rows. What will happen


when the following code is executed? Mark for
Review
DECLARE (1) Points
CURSOR emp_curs IS
SELECT job_id FROM employees;
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
FETCH emp_curs INTO v_job_id;
DBMS_OUTPUT.PUT_LINE(v_job_id);
EXIT WHEN emp_curs%NOTFOUND;
END LOOP;
CLOSE emp_curs;
END;

21 rows of output will be displayed; the first job_id will


be displayed twice.
The block will fail and an error message will be
displayed.
20 job_ids will be displayed.
21 rows of output will be displayed; the last job_id will
be displayed twice. (*)

Incorrect. Refer to Section 6


Lesson 1.

14. Which of the following is a good reason to use two cursors


in a single PL/SQL block? Mark for
Review
(1) Points

To allow rows to be locked as they are FETCHed.


To allow one cursor to be opened twice at the same
time.
It is the only way to declare a cursor with a parameter.
When two tables are related to each other (often by a
foreign key) and we want to produce a multilevel
report using data from both tables. (*)
To speed up the execution of the PL/SQL block.

Incorrect. Refer to Section 6


Lesson 6.
15. Assume your schema contains 25 tables. How many explicit
cursors can you declare and use within a single PL/SQL Mark for
block? Review
(1) Points

As many as you need, but only one of them can be


open at any time.
A maximum of three.
Only one.
As many as you need - there is no limit. (*)
A maximum of 25 (one for each table in your schema).

Incorrect. Refer to Section 6


Lesson 6.

1. User TOM
has Mark for Review
locked a (1) Points
row in the
WORKERS
table.
Now, user
DICK
wants to
open the
following
cursor:
CURSOR c
IS

SELECT
* FROM
workers
FOR
UPDATE
NOWAIT;

What will
happen
when
DICK
opens the
cursor
and tries
to fetch
rows?

DICK's session waits indefinitely.


The c%NOWAIT attribute is set to TRUE.
DICK's session immediately raises an exception. (*)
Both sessions wait for a few seconds; then the system breaks all locks and
both sessions raise an exception.
TOM's session is rolled back. DICK's session successfully fetches rows from
the cursor.

Incorrect. Refer to Section 6 Lesson 5.

2. Examine the following code:


Mark for Review
DECLARE (1) Points
CURSOR c IS SELECT * FROM employees FOR UPDATE;
c_rec c%ROWTYPE;
BEGIN
OPEN c;
FOR i IN 1..20 LOOP
FETCH c INTO c_rec;
IF i = 6 THEN
UPDATE employees SET first_name = 'Joe'
WHERE CURRENT OF c;
END IF;
END LOOP;
CLOSE c;
END;

Which employee row or rows will be updated when this block is executed?

The 6th fetched row will be updated. (*)


No rows will be updated because you locked the rows when the cursor was
opened.
The block will not compile because the cursor should have been declared
.... FOR UPDATE WAIT 5;
The first 6 fetched rows will be updated.
None of these.

Correct

3. You have declared a cursor as SELECT .... FOR UPDATE; You have OPENed the
cursor and locked the FETCHed rows. When are these row locks released? Mark for Review
(1) Points

When another user tries to SELECT the rows


When you CLOSE the cursor
When you explicitly COMMIT or ROLLBACK your transaction (*)
When your block finishes executing
When an UPDATE ... WHERE CURRENT OF cursor_name; is executed

Incorrect. Refer to Section 6 Lesson 5.


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

To allow rows to be locked as they are FETCHed.


It is the only way to declare a cursor with a parameter.
To allow one cursor to be opened twice at the same time.
To speed up the execution of the PL/SQL block.
When two tables are related to each other (often by a foreign key) and we
want to produce a multilevel report using data from both tables. (*)

Incorrect. Refer to Section 6 Lesson 6.

5. Assume your schema contains 25 tables. How many explicit cursors can you
declare and use within a single PL/SQL block? Mark for Review
(1) Points

As many as you need - there is no limit. (*)


A maximum of 25 (one for each table in your schema).
Only one.
As many as you need, but only one of them can be open at any time.
A maximum of three.

Correct

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

A CASE statement
An IF .... ELSE statement
A basic loop which includes OPEN, FETCH, and CLOSE statements
A basic loop which includes FETCH and EXIT WHEN statements (*)

Incorrect. Refer to Section 6 Lesson 1.


7. Place the following statements in the correct sequence:
Mark for Review
A. OPEN my_curs; (1) Points
B. CLOSE my_curs;
C. CURSOR my_curs IS SELECT my_column FROM my_table;
D. FETCH my_curs INTO my_variable;

A,C,D,B
C,D,A,B
C,A,B,D
C,A,D,B (*)

Incorrect. Refer to Section 6 Lesson 1.

8. Which one of the following statements is NOT true?


Mark for Review
(1) Points

You can use ORDER BY when declaring an explicit cursor.


An explicit cursor can select from only one table. No joins are allowed. (*)
An explicit cursor must be DECLAREd before it can be OPENed.
You can not use an INTO clause when declaring an explicit cursor.

Incorrect. Refer to Section 6 Lesson 1.

9. Which of the following best describes the difference between implicit and explicit
cursors? Mark for Review
(1) Points

Implicit cursor are named by the PL/SQL programmer, while explicit cursors
are always named SQL.
Implicit cursors are used for SELECT statements, while explicit cursors are
used for DML statements.
Implicit cursors are defined automatically by Oracle, while explicit cursors
must be declared by the PL/SQL programmer. (*)
Implicit cursors store rows on disk, while explicit cursors store rows in
memory.

Incorrect. Refer to Section 6 Lesson 1.

10. You have declared the following cursor:


Mark for Review
CURSOR country_curs IS (1) Points
SELECT * FROM wf_countries
ORDER BY country_name;
There are over 200 rows in the WF_COUNTRIES table, but you want to fetch and
display only the first 25 rows.

How would you exit from the FETCH loop?

EXIT WHEN country_curs%FOUND(25);


EXIT WHEN country_curs%ROWCOUNT > 25; (*)
WHEN country_curs > 25 THEN EXIT; END IF;
EXIT WHEN ROWCOUNT > 25;

Incorrect. Refer to Section 6 Lesson 2.

11. You can


reference Mark for Review
explicit (1) Points
cursor
attributes
directly in
a SQL
statement.
True or
False?

True
False (*)

Incorrect. Refer to Section 6 Lesson 2.

12. Look at the following code:


Mark for Review
DECLARE (1) Points
CURSOR emp_curs (p_dept_id employees.department_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id;
v_emp_rec emp_curs%ROWTYPE;
v_deptid NUMBER(4) := 50;
BEGIN
OPEN emp_curs( -- Point A --);
....

You want to open the cursor, passing value 50 to the parameter. Which of the
following are correct at Point A?

100 / 2
All of these. (*)
v_deptid
50
Incorrect. Refer to Section 6 Lesson 4.

13. Examine the following declaration of a cursor with a parameter. What should
be coded at Point A? Mark for Review
(1) Points
DECLARE
CURSOR emp_curs(-- Point A --) IS
SELECT * FROM employees
WHERE job_id = p_job_id;

p_job_id VARCHAR2 (*)


job_id VARCHAR2
ST_CLERK'
p_job_id VARCHAR2(25)
p_job_id

Correct

14. You have declared a cursor as follows:


Mark for Review
CURSOR loc_curs IS SELECT * FROM locations; (1) Points

How should you code a FOR loop to use this cursor?

IF loc_rec IN loc_curs LOOP ...


WHILE loc_rec IN loc_curs LOOP ...
FOR loc_rec IN 1 .. loc_curs%ROWCOUNT LOOP ...
FOR loc_curs IN loc_rec LOOP ...
FOR loc_rec IN loc_curs LOOP ... (*)

Incorrect. Refer to Section 6 Lesson 3.

15. What is wrong with the following code?


Mark for Review
DECLARE (1) Points
CURSOR dept_curs IS SELECT * FROM departments;
BEGIN
FOR dept_rec IN dept_curs LOOP
DBMS_OUTPUT.PUT_LINE(dept_curs%ROWCOUNT ||
dept_rec.department_name):
END LOOP;
DBMS_OUTPUT.PUT_LINE(dept_rec.department_id);
END;

The cursor DEPT_CURS has not been opened.


The implicitly declared record DEPT_REC cannot be referenced outside
the cursor FOR loop. (*)
You cannot use %ROWCOUNT with a cursor FOR loop.
Nothing is wrong, this code will execute successfully.
The cursor DEPT_CURS has not been closed.

Incorrect. Refer to Section 6 Lesson 3.

Section 7 Quiz
(Answer all questions in this section)

1. Examine the followiing code. Which exception handlers would successfully trap the
exception which will be raised when this code is executed? (Choose two.) Mark for Review
(1) Points
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_FETCH
WHEN OTHERS (*)
WHEN CURSOR_NOT_OPEN
WHEN INVALID_CURSOR (*)
WHEN NO_DATA_FOUND

Incorrect. Refer to Section 7 Lesson 2.

2. Examine the following code. What message or messages will be displayed when this
code is executed? Mark for Review
(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;

An error occurred
Attempt to divide by zero (*)
No message will be displayed
Attempt to divide by zero No rows were found
No rows were found

Incorrect. Refer to Section 7 Lesson 2.

3. What is the correct syntax to associate an exception named EXCEPNAME with the non-
predefined Oracle Server error ORA-02292? Mark for Review
(1) Points

SQLCODE (-2292, excepname);


PRAGMA EXCEPTION_INIT (excepname, -2292) (*)
RAISE_APPLICATION_ERROR (-2292, excepname);
WHEN (-2292, excepname) THEN …

Incorrect. Refer to Section 7 Lesson 2.

4. An attempt to insert a null value into a NOT NULL table column raises an ORA-01400
exception. How can you code an exception handler to trap this exception? Mark for Review
(1) Points

Test for WHEN ORA-1400 in the exception section.


Declare a variable e_null_excep of type VARCHAR2, associate it with ORA-01400
using a PRAGMA directive, and test for WHEN e_null_excep in the exception
section.
Declare a variable e_null_excep of type EXCEPTION, associate it with ORA-01400
using a PRAGMA directive, and test for WHEN e_null_excep in the exception
section. (*)
Declare a variable as follows: e_null_excep EXCEPTION := -01400; Then test for
WHEN e_null_excep in the exception section.

Incorrect. Refer to Section 7 Lesson 2.

5. An attempt to update an employee's salary to a negative value will violate a check


constraint and raise an ORA-02290 exception. Which of the following is a correct Mark for Review
definition of a handler for this exception? (1) Points

DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,02290);
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);
(*)
DECLARE
e_sal_excep EXCEPTION;
PRAGMA_EXCEPTION_INIT(e_sal_exception,-02290);
DECLARE
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);
e_sal_excep EXCEPTION;
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(-02290,e_sal_excep);

Incorrect. Refer to Section 7 Lesson 2.

6. Which of
the Mark for Review
following (1) Points
EXCEPTION
sections is
constructed
correctly?
(Choose
three.)

(Choose all correct answers)

EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
END;

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

(*)
EXCEPTION
WHEN OTHERS THEN statement_1;
END;

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

Incorrect. Refer to Section 7 Lesson 1.


7. Which of the following EXCEPTION sections are constructed correctly? (Choose
two.) Mark for Review
(1) Points

(Choose all correct answers)

EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
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_2;
WHEN NO_DATA_FOUND THEN statement_1;
END;

Incorrect. Refer to Section 7 Lesson 1.

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.


The programmer makes a spelling mistake while writiing the PL/SQL code.
An error occurs during execution which disrupts the normal operation of
the program. (*)
A DML statement does not modify any rows.

Incorrect. Refer to Section 7 Lesson 1.

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


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

TRUE (*)
FALSE

Correct

10. Exceptions declared in a block are considered local to that block, and global to
all its sub-blocks. True or False? Mark for Review
(1) Points

True (*)
False

Correct

11. Non-predefined
Oracle Server Mark for Review
errors (associated (1) Points
with Oracle error
numbers by
PRAGMA
EXCEPTION_INIT)
can be declared
and raised in
inner blocks and
handled in outer
blocks. True or
False?

True
False (*)

Incorrect. Refer to Section 7 Lesson 4.

12. The following three steps must be performed to use a user-defined


exception: - Raise the exception - Handle the exception - Declare the Mark for Review
exception In what sequence must these steps be performed? (1) Points

The steps can be performed in any order.


Raise, Handle, Declare
Declare, Raise, Handle (*)
Handle, Raise, Declare

Incorrect. Refer to Section 7 Lesson 3.

13. What is a user-defined exception?


Mark for Review
(1) Points
An exception handler which the user (the programmer) includes in
the EXCEPTION section.
A predefined Oracle server exception such as NO_DATA_FOUND.
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.

Incorrect. Refer to Section 7 Lesson 3.

14. A user-defined exception can be raised:


Mark for Review
A. In the declaration section (1) Points
B. In the executable section
C. In the exception section

B
A and C
C
B and C (*)
A and B

Incorrect. Refer to Section 7 Lesson 3.

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


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

True
False (*)

Incorrect. Refer to Section 7 Lesson 3.

1. Exceptions
declared Mark for Review
in a block (1) Points
are
considered
local to
that block,
and global
to all its
sub-
blocks.
True or
False?
True (*)
False

Correct

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


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

True (*)
False

Correct

3. You cannot use SQLCODE or SQLERRM directly in an SQL statement. Instead,


you must assign their values to local variables, then use the variables in the SQL Mark for Review
statement (1) Points

True (*)
False

Correct

4. How can you retrieve the error code and error message of any Oracle Server
exception? Mark for Review
(1) Points

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

Incorrect. Refer to Section 7 Lesson 2.

5. Which type of exception MUST be explicitly raised by the PL/SQL programmer?


Mark for Review
(1) Points

Non-predefined Oracle server errors such as ORA-01203


User-defined exceptions (*)
All of these.
Predefined Oracle server errors such as TOO_MANY_ROWS
Incorrect. Refer to Section 7 Lesson 2.

6. Which kinds of
exceptions are Mark for Review
raised (1) Points
implicitly (i.e.,
automatically)?
(Choose two.)

(Choose all correct answers)

All errors
Predefined Oracle Server errors such as NO_DATA_FOUND (*)
User-defined errors
Non-predefined Oracle Server errors such as ORA-01400 (*)

Incorrect. Refer to Section 7 Lesson 2.

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

Incorrect. Refer to Section 7 Lesson 2.

8. What is a user-defined exception?


Mark for Review
(1) Points

An exception which has a predefined Oracle error number but no


predefined name.
An exception which is not raised automatically by the Oracle server,
but must be declared and raised explicitly by the PL/SQL programmer.
(*)
A predefined Oracle server exception such as NO_DATA_FOUND.
An exception handler which the user (the programmer) includes in the
EXCEPTION section.

Incorrect. Refer to Section 7 Lesson 3.


9. What will be displayed when the following code is executed?
Mark for Review
DECLARE (1) Points
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;

Message 1
Message 3
Message 4
The code will not execute because it contains at least one syntax error.
Message 1
Message 2
Message 3
Message 4
The code will execute but will return an unhandled exception to the
calling environment.

(*)
Message 1
Message 3

Incorrect. Refer to Section 7 Lesson 3.

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

Incorrect. Refer to Section 7 Lesson 3.

11. How are


user- Mark for Review
defined (1) Points
exceptions
raised ?

By PRAGMA EXCEPTION_INIT
By RAISE exception_name; (*)
By DECLARE e_my_excep EXCEPTION;
None of these. They are raised automatically by the Oracle server.

Incorrect. Refer to Section 7 Lesson 3.

12. Which of these exceptions can be handled by an EXCEPTION section in a


PL/SQL block? Mark for Review
(1) Points

Any other kind of exception that can occur within the block
An attempt is made to divide by zero
A SELECT statement returns no rows
All of these. (*)
None of these.

Incorrect. Refer to Section 7 Lesson 1.

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


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

TRUE (*)
FALSE

Correct

14. Examine the following code. Why does this exception handler not follow good
practice guidelines? Mark for Review
(1) Points
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;

The exception handler should COMMIT the transaction.


employee_id 999 does not exist in the employees table.
You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.
The exception handler should test for the named exception
NO_DATA_FOUND. (*)

Incorrect. Refer to Section 7 Lesson 1.

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

TRUE
FALSE (*)

Incorrect. Refer to Section 7 Lesson 1.

Section 8 Quiz
(Answer all questions in this section)

1. PL/SQL subprograms, unlike anonymous blocks, are compiled each time they are
executed. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 8 Lesson 1.

2. What is another name for a nested subprogram?


Mark for Review
(1) Points

Hosted subprogram
Limited subprogram
Local subprogram (*)

Incorrect. Refer to Section 8 Lesson 1.

3. Which of the following are benefits of using PL/SQL subprograms rather than
anonymous blocks? (Choose three.) Mark for Review
(1) Points

(Choose all correct answers)


Easier code maintenance (*)
Stored externally
Better data security (*)
Code reuse (*)
Do not need to define exceptions

Incorrect. Refer to Section 8 Lesson 1.

4. One PL/SQL subprogram can be invoked from within many applications. True or False?
Mark for Review
(1) Points

TRUE (*)
FALSE

Correct

5. A programmer creates a PL/SQL subprogram which is compiled and stored in the


database. Two separate users then execute an application which invokes this Mark for Review
subprogram four times. How many times must the subprogram be recompiled? (1) Points

One time
Two times
Four times
Zero times (*)
Eight times

Incorrect. Refer to Section 8 Lesson 1.

6. Examine the following


procedure: Mark for Review
(1) Points
CREATE OR REPLACE
PROCEDURE
smallproc
(p_param IN
NUMBER)
IS
BEGIN ....

The procedure is
invoked by:
DECLARE
v_param NUMBER :=
20;
BEGIN
smallproc(v_param);
END;

Which of the following


statements is true?

p_param is a parameter and v_param is an argument


p_param is a formal parameter and v_param is an actual
parameter (*)
p_param is an actual parameter and v_param is a formal
parameter
p_param is a formal parameter and 20 is an actual parameter
p_param and v_param are both formal parameters, while 20 is
an actual parameter

Incorrect. Refer to Section 8 Lesson 2.

7. A procedure will execute faster if it has at least one parameter.


Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 8 Lesson 2.

8. You want to create a procedure named SOMEPROC which accepts a


single parameter named SOMEPARM. The parameter can be up to Mark for Review
100 characters long. Which of the following is correct syntax to do (1) Points
this?

CREATE PROCEDURE someproc


(someparm varchar2)
IS
BEGIN ...
(*)
CREATE PROCEDURE someproc
(someparm varchar2(100) )
IS
BEGIN...
CREATE PROCEDURE someproc
someparm varchar2(100);
IS
BEGIN...
CREATE PROCEDURE someproc
(someparm 100)
IS
BEGIN ...
CREATE PROCEDURE someproc
IS
(someparm VARCHAR2;)
BEGIN...

Correct

9. A procedure has been created as:


Mark for Review
CREATE PROCEDURE myproc (1) Points
(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, v_right);
All of the above (*)
myproc(p_left, p_right);
myproc(v_left, 30);

Incorrect. Refer to Section 8 Lesson 2.

10. Parameters are a special form of a variable, whose input values are
initialized by the calling environment when the subprogram is called, Mark for Review
and whose output values are returned to the calling environment (1) Points
when the subprogram returns control to the caller.

True (*)
False

Correct

11. What will happen when


the following procedure is Mark for Review
called as format_phone (1) Points
(8005551234)?

CREATE OR REPLACE
PROCEDURE
format_phone
(p_phone_no IN OUT
VARCHAR2) IS
BEGIN
p_phone_no :=
SUBSTR(p_phone_no,1,3)
||
'.' ||
SUBSTR(p_phone_no,4,3)
||
'.' ||
SUBSTR(p_phone_no,7);
END format_phone;

The phone number (800) 555-1234 is printed to the


screen.
The phone number 800.555.1234 is placed into the
p_phone_no variable. (*)
The phone number 800.555.1234 is printed to the screen.
The procedure does not execute because the input
variable is not properly declared.

Incorrect. Refer to Section 8 Lesson


3.

12. Procedure SOMEPROC has five parameters named A, B, C, D, E


in that order. The procedure was called as follows: Mark for Review
(1) Points
SOMEPROC(10,20,30,D=>50,E=>60);

How was parameter D referenced?

Positionally
A combination of named and defaulted
A combination of positionally and named
Named (*)
Defaulted

Incorrect. Refer to Section 8 Lesson


3.

13. Suppose you set up a parameter with an explicit OUT mode.


What is true about that parameter? Mark for Review
(1) Points

It inherits its type from the matching IN parameter.


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 must be the same type as the matching IN parameter.

Incorrect. Refer to Section 8 Lesson


3.

14. Which of the following statements about IN OUT parameters


are true? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)

The parameter value can be returned as a new value that


is set within the procedure. (*)
The parameter value can be returned as the original
unchanged value. (*)
The parameter value passed into the subprogram is
always returned unchanged to the calling environment.
The data type for the parameter must be VARCHAR2.

Correct

15. When creating a procedure, where in the code must the


parameters be listed? Mark for Review
(1) Points

Before the procedure name


After the keyword PROCEDURE
After the procedure name (*)
After the keyword IS or AS

Incorrect. Refer to Section 8 Lesson


3.

1. A procedure is invoked by this


command: Mark for Review
(1) Points
myproc('Smith',salary=>5000);

What is the method of passing


parameters used here?

None of these.
Named
Positional
A combination of positional and named (*)

Incorrect. Refer to Section 8


Lesson 3.

2. Suppose you set up a parameter with an explicit IN mode.


What is true about that parameter? Mark for Review
(1) Points

It must have a DEFAULT value.


It must be the same type as the matching OUT
parameter.
It inherits its type from the matching OUT parameter.
It acts like a constant (its value cannot be changed
inside the subprogram). (*)
It cannot have a DEFAULT value.

Incorrect. Refer to Section 8


Lesson 3.

3. Which parameter mode is the default?


Mark for Review
(1) Points

CONSTANT
NUMBER
OUT
IN (*)
VARIABLE

Incorrect. Refer to Section 8


Lesson 3.

4. Procedure SOMEPROC has five parameters named A, B, C,


D, E in that order. The procedure was called as follows: Mark for Review
(1) Points
SOMEPROC(10,20,30,D=>50,E=>60);

How was parameter B referenced?

Positional (*)
A combination of named and defaulted
Defaulted
A combination of positionally and named
Named

Correct

5. The following procedure has been created:


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

Incorrect. Refer to Section 8


Lesson 3.

6. A programmer wants to create a


PL/SQL procedure named Mark for Review
EMP_PROC. What will happen (1) Points
when the following code is
executed?

CREATE OR REPLACE
PROCEDURE emp_proc IS
v_salary
employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary
FROM employees
WHERE employee_id = 999;
DBMS_OUTPUT.PUT_LINE('The
salary is: ' || v_salary);
END;

The procedure will be created successfully. (*)


The statement will fail because the last line of code
should be END emp_proc;
The statement will fail because the procedure does
not have any parameters.
The statement will raise a NO_DATA_FOUND
exception because employee_id 999 does not exist.
The statement will fail because you cannot declare
variables such as v_salary inside a procedure.

Correct

7. Procedures are generally used to perform what?


Mark for Review
(1) Points

All of these.
An action (*)
A return of values
None of these.
A SELECT statement

Incorrect. Refer to Section 8


Lesson 1.

8. A programmer wants to create a PL/SQL procedure


named MY_PROC. What will happen when the following Mark for Review
code is executed? (1) Points

CREATE OR REPLACE PROCEDURE my_proc IS


v_empid employees.empid%TYPE;
BEGIN
SELECT employee_id INTO v_empid FROM
employees
WHERE region_id = 999;
DBMS_OUTPUT.PUT_LINE('The salary is: ' ||
v_salary);

The statement will raise a NO_DATA_FOUND


exception because region_id 999 does not exist.
The statement will fail because you cannot declare
variables such as v_empid inside a procedure.
The statement will fail because the last line of code
should be END my_proc; (*)

Incorrect. Refer to Section 8


Lesson 1.

9. Subprograms and anonymous blocks can be called by


other applications. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 8


Lesson 1.

10. A stored procedure add_dept may be invoked by the


following command in Application Express. True or Mark for Review
False? (1) Points

BEGIN
add_dept;
END;

True (*)
False

Correct
11. Which of
the Mark for Review
following (1) Points
can NOT
be used as
the
datatype of
a
procedure
parameter?

A non-SQL datatype such as BOOLEAN


The name of another procedure (*)
A large object datatype such as CLOB
A PLSQL record defined using %ROWTYPE

Incorrect. Refer to Section 8 Lesson 2.

12. Which of the following can be used as an argument for a procedure


parameter? Mark for Review
(1) Points

An expression
A literal value
None of these.
All of these. (*)
The name of a variable

Incorrect. Refer to Section 8 Lesson 2.

13. Which of the following statements about actual parameters is NOT true?
Mark for Review
(1) Points

An actual parameter can have a Boolean datatype.


An actual parameter must be the name of a variable. (*)
An actual parameter can have a TIMESTAMP datatype.
An actual parameter is declared in the calling environment, not in the
called procedure.
The datatypes of an actual parameter and its formal parameter must be
compatible.

Incorrect. Refer to Section 8 Lesson 2.

14. You have created procedure MYPROC with a single parameter PARM1
NUMBER. Now you want to add a second parameter to the procedure. Which Mark for Review
of the following will change the procedure successfully? (1) Points
ALTER PROCEDURE myproc ADD (parm2 NUMBER);
CREATE OR REPLACE PROCEDURE myproc
(parm1 NUMBER, parm2 NUMBER);
(You do not need to repeat the detailed code of the procedure, only the
header)
The procedure cannot be modified. Once a procedure has been created,
the number of parameters cannot be changed.
CREATE OR REPLACE PROCEDURE myproc
(parm1 NUMBER, parm2 NUMBER)
IS
BEGIN ... (*)
REPLACE PROCEDURE myproc
(parm1 NUMBER, parm2 NUMBER)
IS
BEGIN ...

Incorrect. Refer to Section 8 Lesson 2.

15. Which of the following best describes the difference between a parameter and
an argument? Mark for Review
(1) Points

A parameter is a variable that accepts a value that is passed to it, while


an argument is the value that is passed. (*)
There is no difference; parameters and arguments are the same thing.
They are both names of variables. A parameter is passed into the
procedure, while an argument is passed out of the procedure.
A parameter is the name of a variable, while an argument is the datatype
of that variable.

Correct

Section 9 Quiz
(Answer all questions in this section)

1. A stored function:
Mark for Review
(1) Points

must return one and only one value. (*)


cannot be called in a SQL statement.
must have at least one IN parameter.
is called as a standalone executable statement.

Correct
2. Which of the following is a difference between a procedure and a function?
Mark for Review
(1) Points

A procedure can have default values for parameters, while a function cannot.
A function must return a value; a procedure may or may not. (*)
A function cannot be used within a SQL statement; a procedure can be used
within SQL.
Functions cannot be nested; procedures can be nested to at least 8 levels.
An explicit cursor can be declared in a procedure, but not in a function.

Incorrect. Refer to Section 9 Lesson 1.

3. You try to create a function named MYFUNC. The function does not compile correctly
because there are errors in your code. Which Dictionary view can you query to see the Mark for Review
errors? (1) Points

USER_COMPILES
USER_SOURCE
USER_DEPENDENCIES
USER_OBJECTS
USER_ERRORS (*)

Incorrect. Refer to Section 9 Lesson 1.

4. USERB creates a function called SEL_PROC which includes the statement:


Mark for Review
SELECT ... FROM usera.employees ...; (1) Points

USERC needs to execute UserB's procedure. What privileges are needed for this to work
correctly? (Choose two.)

(Choose all correct answers)

UserB needs SELECT on userA.employees (*)


UserC needs EXECUTE on Userb
UserC needs SELECT on userA.employees
UserA needs EXECUTE on userB.sel_proc
UserC needs EXECUTE on userB.sel_proc (*)

Incorrect. Refer to Section 9 Lesson 5.


5. When a database object is first created, only its owner (creator) and the Database
Administrator are privileged to use it. True or False? Mark for Review
(1) Points

True (*)
False

Correct

6. Why will the


following Mark for Review
statement (1) Points
fail?

SELECT
employee_id,
tax(p_value
=> salary)
FROM
employees;

The data type for the tax variable does not match the data type for
salary.
The statement will execute and not fail.
User-defined functions are not allowed in the SELECT clause.
Name notation is not allowed. (*)

Incorrect. Refer to Section 9 Lesson 2.

7. When creating a user-defined function that will be called from a SQL


statement, the size of the returned values may be up to the size of any Mark for Review
PL/SQL data type. True or False? (1) Points

True
False (*)

Incorrect. Refer to Section 9 Lesson 2.

8. A benefit of user-defined functions is that the function can accept any SQL or
PL/SQL data type. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 9 Lesson 2.


9. JOHN and FRED are database users. JOHN grants SELECT privilege to FRED
on three of his (JOHN's) tables. Which Dictionary view should FRED query to Mark for Review
see the names of JOHN's three tables? (1) Points

USER_TABLES
ALL_TABLES (*)
DBA_TABLES
DICTIONARY
FRED_TABLES

Incorrect. Refer to Section 9 Lesson 3.

10. You want to see the names of all the columns in a table in your schema. You
want to query the Dictionary instead of using the DESCRIBE command. Which Mark for Review
Dictionary view should you query? (1) Points

USER_TABLES
USER_OBJECTS
USER_TAB_COLS (*)
USER_COLUMNS

Incorrect. Refer to Section 9 Lesson 3.

11. Which of
the Mark for Review
following (1) Points
will tell
you how
many
functions
you
own?

SELECT COUNT(*) FROM USER_OBJECTS WHERE


OBJECT_TYPE='FUNCTION'; (*)
SELECT COUNT(*) FROM USER_OBJECTS;
SELECT FUNCTIONS FROM USER_OBJECTS;
SELECT COUNT(*) FROM USER_PROCEDURES;
SELECT COUNT(*) FROM USER_FUNCTIONS;

Correct
12. You want to see the names, modes, and data types of the formal parameters of
function MY_FUNC in your schema. How can you do this? (Choose two) Mark for Review
(1) Points

(Choose all correct answers)

Query USER_FUNCTIONS
Query USER_SOURCE (*)
Query USER_PARAMETERS
DESCRIBE my_func; (*)
SHOW PARAMETER my_func;

Incorrect. Refer to Section 9 Lesson 4.

13. Which dictionary view will list all the PL/SQL subprograms in your schema?
Mark for Review
(1) Points

user_subprograms
user_dependencies
user_objects (*)
user_source
user_procedures

Incorrect. Refer to Section 9 Lesson 4.

14. Which statement is true regarding the following subprogram?


Mark for Review
PROCEDURE at_proc IS (1) Points
PRAGMA AUTONOMOUS_TRANSACTION;
dept_id NUMBER := 90;
BEGIN
UPDATE ...
INSERT ...
END at_proc;

The subprogram's success depends on the calling program.


The subprogram cannot do a COMMIT.
The subprogram will fail because the RETURN is not specified.
The subprogram's success is independent of the calling program. (*)

Incorrect. Refer to Section 9 Lesson 6.


15. What will happen when the following procedure is executed?
Mark for Review
PROCEDURE log_usage (p_card_id NUMBER, p_loc NUMBER) (1) Points
IS
PRAGMA AUTONOMOUS_TRANSACTION
BEGIN
INSERT INTO log_table (card_id, location, tran_date)
VALUES (p_card_id, p_loc, SYSDATE);
COMMIT;
END log_usage;

The subprogram will fail because the PRAGMA statement must be before
IS.
The program will compile successfully.
The subprogram will fail because it is missing AUTHID CURRENT_USER
before IS.
The compilation will fail because a semicolon after
AUTONOMOUS_TRANSACTION is required. (*)

Incorrect. Refer to Section 9 Lesson 6.


1. Which
view Mark for Review
would you (1) Points
query to
see the
detailed
code of a
procedure?

user_errors
user_procedures
user_source (*)
user_objects
user_dependencies

Incorrect. Refer to Section 9 Lesson 4.

2. Examine the following code (the code of CHILD2 is not shown):


Mark for Review
CREATE PROCEDURE child1 (1) Points
IS v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 9999;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END child1;

CREATE PROCEDURE parent


IS BEGIN
child1;
child2;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END parent;

Employee_id 9999 does not exist. What happens when PARENT is executed?

CHILD1 ends abruptly, and then PARENT also ends abruptly with an
unhandled exception.
PARENT handles the exception, and then CHILD1 resumes execution.
CHILD1 handles the exception successfully and ends. PARENT continues to
execute and invokes CHILD2. (*)
PARENT fails to compile because you cannot have the same exception
handler in two separate subprograms.
CHILD1 ends abruptly, and PARENT handles the exception successfully and
ends. CHILD2 does not execute.

Incorrect. Refer to Section 9 Lesson 4.

3. The function avg_ann_sal returns the average annual salary for a particular
department. The example below is a valid use of this function. True or False? Mark for Review
(1) Points
SELECT first_name, last_name
FROM employees
WHERE avg_ann_sal(20) > 15000;

True (*)
False

Correct

4. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE


FUNCTION double_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER Mark for Review
IS BEGIN RETURN(p_salary * 2); END; Which of the following calls to (1) Points
DOUBLE_SAL will NOT work?

None, they will all work (*)


SELECT * FROM employees WHERE double_sal(salary) > 20000;
SELECT last_name, double_sal(salary) FROM employees;
SELECT * FROM employees ORDER BY double_sal(salary) DESC;
UPDATE employees SET salary = double_sal(salary);

Correct

5. Why will the following statement fail?


Mark for Review
SELECT employee_id, tax(p_value => salary) (1) Points
FROM employees;
The statement will execute and not fail.
User-defined functions are not allowed in the SELECT clause.
The data type for the tax variable does not match the data type for salary.
Name notation is not allowed. (*)

Incorrect. Refer to Section 9 Lesson 2.

6. User REYHAN
creates the Mark for Review
following (1) Points
procedure:

CREATE
PROCEDURE
proc1
AUTHID
CURRENT_USER
IS
v_count
NUMBER;
BEGIN
SELECT
COUNT(*) INTO
v_count
FROM
tom.employees;
END;

User BILL wants


to execute this
procedure. What
privileges will
BILL need?

None of these. The procedure will fail to compile because REYHAN


does not have SELECT privilege on TOM.EMPLOYEES.
EXECUTE on REYHAN.PROC1
BILL needs no privileges
EXECUTE on REYHAN.PROC1 and SELECT on TOM.EMPLOYEES (*)
SELECT on TOM.EMPLOYEES

Incorrect. Refer to Section 9 Lesson 6.

7. How do you specify that you want a procedure MYPROCA to use Invoker's
Rights? Mark for Review
(1) Points

GRANT INVOKER TO myprocA;


ALTER PROCEDURE myproca TO INVOKER;
CREATE OR REPLACE PROCEDURE myproca
AUTHID CURRENT_USER IS...

(*)
Invoker's Rights are the default, therefore no extra code is needed.
CREATE OR REPLACE PROCEDURE myproca
AUTHID OWNER IS...

Incorrect. Refer to Section 9 Lesson 6.

8. Function GET_JOB accepts an employee id as input and returns that


employee's job id. Which of the following calls to the function will NOT Mark for Review
work? (1) Points

v_job_id := get_job(100);
get_job(100,v_job_id); (*)
IF get_job(100) = 'IT_PROG' THEN ...
DBMS_OUTPUT.PUT_LINE(get_job(100));

Incorrect. Refer to Section 9 Lesson 1.

9. Function MYFUNC1 has been created, but has failed to compile because it
contains syntax errors. We now try to create procedure MYPROC1 which Mark for Review
invokes this function. Which of the following statements is true? (1) Points

MYPROC1 will fail to compile because the function is invalid. (*)


MYPROC1 will compile and execute succesfully.
MYPROC1 will compile correctly, but will fail when it is executed.
MYPROC1 will compile and execute successfully, except that the call
to MYFUNC1 will be treated as a comment and ignored.

Correct

10. You try to create a function named MYFUNC. The function does not
compile correctly because there are errors in your code. Which Dictionary Mark for Review
view can you query to see the errors? (1) Points

USER_COMPILES
USER_DEPENDENCIES
USER_SOURCE
USER_OBJECTS
USER_ERRORS (*)
Incorrect. Refer to Section 9 Lesson 1.

11. Which
object Mark for Review
privilege (1) Points
can be
granted
on a
single
column
of a
table?

DELETE
CREATE
DROP
UPDATE (*)
SELECT

Incorrect. Refer to Section 9 Lesson 5.

12. When a database object is first created, only its owner (creator) and the
Database Administrator are privileged to use it. True or False? Mark for Review
(1) Points

True (*)
False

Correct

13. JOHN and FRED are database users. JOHN grants SELECT privilege to FRED on
three of his (JOHN's) tables. Which Dictionary view should FRED query to see the Mark for Review
names of JOHN's three tables? (1) Points

DBA_TABLES
ALL_TABLES (*)
FRED_TABLES
DICTIONARY
USER_TABLES

Incorrect. Refer to Section 9 Lesson 3.

14. You want to see the names of all the columns in a table in your schema. You
want to query the Dictionary instead of using the DESCRIBE command. Which Mark for Review
Dictionary view should you query? (1) Points
USER_TAB_COLS (*)
USER_COLUMNS
USER_TABLES
USER_OBJECTS

Correct

15. A user executes the following statement:


Mark for Review
CREATE INDEX fn_index ON employees(first_name); (1) Points

What output will the following statement now display:

SELECT index_name
FROM user_indexes
WHERE index_name LIKE 'fn%';

FN_INDEX
fn_index FN_INDEX
No output will be displayed (*)
fn_index

Incorrect. Refer to Section 9 Lesson 3.

Section 10 Quiz
(Answer all questions in this section)

1. In which component of a package is the full definition of a public procedure written?


Mark for Review
(1) Points

Neither the body nor the specification


Specification
Both the body and the specification
Body (*)

Incorrect. Refer to Section 10 Lesson 1.

2. Which of the following can be included in a package?


Mark for Review
(1) Points
All of these. (*)
variables
Exceptions
procedures
PL/SQL types

Correct

3. Package Specification DEPT_PACK was created by the following code:


Mark for Review
CREATE OR REPLACE PACKAGE dept_pack IS (1) Points
PROCEDURE ins_dept(p_deptno IN NUMBER);
FUNCTION get_dept(p_deptno IN NUMBER) RETURN VARCHAR2;
END dept_pack;

Which of the following are correct syntax for invoking the package subprograms?
(Choose two.)

(Choose all correct answers)

DECLARE
v_deptname VARCHAR2(20);
BEGIN
v_deptname := get_dept(50);
END;
BEGIN
dept_pack.ins_dept(20);
END;

(*)
BEGIN
dept_pack.get_dept(20);
END;
CREATE PROCEDURE dept_proc IS
v_deptname VARCHAR2(20);
BEGIN
v_deptname := dept_pack.get_dept(40);
END;

(*)
BEGIN
dept_pack(30);
END;

Incorrect. Refer to Section 10 Lesson 1.

4. To be able to invoke a package subprogram from outside the package, it must be


declared in the package: Mark for Review
(1) Points

Body and the specification (*)


None of these.
Body
Specification

Correct

5. A number variable declared in a package is initialized to NULL unless assigned another


value. True or False? Mark for Review
(1) Points

True (*)
False

Correct

6. When
using a Mark for Review
package (1) Points
function in
DML
statements,
which rules
must you
follow?
(Choose
three)

(Choose all correct answers)

Can read or modify the table being changed by that DML statement
Changes to a package variable could have an impact on another stored
function (*)
Must not end the current transaction (*)
Cannot execute a DML statement or modify the database (*)

Incorrect. Refer to Section 10 Lesson 3.

7. A public function in a package is invoked from within a SQL statement. The


function's code can include a COMMIT statement. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 10 Lesson 3.


8. Which two of these declarations cannot be in the same package specification?
Mark for Review
1. PROCEDURE myproc (p1 NUMBER, p2 VARCHAR2); (1) Points
2. PROCEDURE myproc (p1 VARCHAR2, p2 NUMBER);
3. PROCEDURE myproc (p1 NUMBER, p2 CHAR);
4. PROCEDURE myproc (p1 NUMBER);

1 and 3 (*)
2 and 3
1 and 4
3 and 4
1 and 2

Correct

9. Which of the following are not allowed in a bodiless package? (Choose three)
Mark for Review
(1) Points

(Choose all correct answers)

Subprograms (*)
Private variables (*)
User-defined exceptions
Global variables
DML statements (*)

Incorrect. Refer to Section 10 Lesson 3.

10. An package initialization block automatically executes once and is used to


initialize public and private package variables. True or False? Mark for Review
(1) Points

True (*)
False

Correct

11. Your schema


contains four Mark for Review
packages, (1) Points
each having a
specification
and a body.
You have also
been granted
privileges to
access three
packages (and
their bodies)
in other users'
schemas.
What will be
displayed by
the following
query?

SELECT
COUNT(*)
FROM
ALL_OBJECTS
WHERE
object_type
LIKE 'PACK%'
AND owner
<> USER;

3
6 (*)
7
14
0

Incorrect. Refer to Section 10 Lesson 2.

12. Which of the following will display the detailed code of the subprograms in
package DEPTPACK in your schema ? Mark for Review
(1) Points

SELECT text FROM USER_SOURCE


WHERE name = 'DEPTPACK'
AND type = 'BODY'
ORDER BY line;
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'PACKAGE BODY'
ORDER BY line;

(*)
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'PACKAGE'
ORDER BY line;
SELECT text FROM USER_SOURCE
WHERE object_name = 'DEPTPACK'
AND object_type = 'PACKAGE BODY'
ORDER BY line;
Incorrect. Refer to Section 10 Lesson 2.

13. Package NEWPACK contains several procedures and functions, including


private function PRIVFUNC. From where can PRIVFUNC be invoked? Mark for Review
(Choose two.) (1) Points

(Choose all correct answers)

From any function in NEWPACK (*)


From any procedure in NEWPACK (*)
From any public procedure in another package
From an anonymous block
From any private function in another package

Correct

14. When one component of a package is called, all the package's components
are loaded into memory. True or False? Mark for Review
(1) Points

True (*)
False

Correct

15. A local variable declared within a procedure in a package can be


referenced by any other component of that package. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 10 Lesson 2.

1. Package
Specification Mark for Review
DEPT_PACK was (1) Points
created by the
following code:

CREATE OR
REPLACE PACKAGE
dept_pack IS
PROCEDURE
ins_dept(p_deptno
IN NUMBER);
FUNCTION
get_dept(p_deptno
IN NUMBER)
RETURN
VARCHAR2;
END dept_pack;

Which of the
following are
correct syntax for
invoking the
package
subprograms?
(Choose two.)

(Choose all correct answers)

BEGIN
dept_pack.get_dept(20);
END;
DECLARE
v_deptname VARCHAR2(20);
BEGIN
v_deptname := get_dept(50);
END;
CREATE PROCEDURE dept_proc IS
v_deptname VARCHAR2(20);
BEGIN
v_deptname := dept_pack.get_dept(40);
END;

(*)
BEGIN
dept_pack.ins_dept(20);
END;

(*)
BEGIN
dept_pack(30);
END;

Incorrect. Refer to Section 10 Lesson 1.

2. The two parts of a package are stored as separate objects in the


database. True or False? Mark for Review
(1) Points

True (*)
False

Correct
3. What is wrong with the following syntax for creating a package
specification? Mark for Review
(1) Points
CREATE OR REPLACE mypack IS
g_constant1 NUMBER(6) := 100;
PROCEDURE proc1 (p_param1 IN VARCHAR2);
PROCEDURE proc2;
END mypack;

The first line should be:


CREATE OR REPLACE PACKAGE SPECIFICATION mypack IS
You cannot declare constants in the specification.
The keyword PACKAGE is missing.

(*)
Nothing is wrong, this code contains no errors.
A package must contain at least one function.

Incorrect. Refer to Section 10 Lesson 1.

4. In which component of a package is the full definition of a public


procedure written? Mark for Review
(1) Points

Body (*)
Neither the body nor the specification
Specification
Both the body and the specification

Correct

5. Which of the following are good reasons for creating and using
Packages? Mark for Review
(1) Points
A. Related procedures, functions, and variables can be grouped
together as a single unit
B. We can recompile the package body without having to
recompile the specification
C. We can create packages without needing any system privileges
D. The detailed package body code is invisible to the calling
environment.

A, B, and C
A, B, C, and D
A, B, and D (*)
A and B
A and C

Incorrect. Refer to Section 10 Lesson 1.

6. Your schema
contains a Mark for Review
package (1) Points
called
EMP_PKG.
You want to
remove the
package
body but not
the
specification.
The correct
syntax to do
this is:
DROP BODY
emp_pkg;
True or
False?

True
False (*)

Incorrect. Refer to Section 10 Lesson 2.

7. Examine the following package specification:


Mark for Review
CREATE OR REPLACE PACKAGE taxpack IS (1) Points
CURSOR empcurs IS SELECT * FROM employees;
PROCEDURE taxproc;
END mypack;

The package body of TAXPACK also includes a function called TAXFUNC.


Which one of the following statements is NOT true?

The package will not compile because you cannot declare a cursor in the
specification.

(*)
TAXPROC can open the cursor.
The procedure can be invoked by:

BEGIN
taxpack.taxproc;
END;
TAXPROC can invoke TAXFUNC if TAXPROC is coded before TAXFUNC.
TAXPROC is public and TAXFUNC is private.
Correct

8. A local variable defined inside a package procedure is visible to the calling


environment. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 10 Lesson 2.

9. When a change is made to the detailed code of a public procedure in a


package (but not to the procedure's name or parameters), both the Mark for Review
specification and the body must be recompiled. True or False? (1) Points

True
False (*)

Incorrect. Refer to Section 10 Lesson 2.

10. A local variable declared within a procedure in a package can be referenced


by any other component of that package. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 10 Lesson 2.

11. The
package Mark for Review
name (1) Points
must be
included
when
calling a
package
function
from a
SELECT
statement
executed
outside
the
package.
True or
False?
True (*)
False

Correct

12. Package FORWARD_PACK contains two procedures: PROC1 is public while


PROC2 is private (not declared in the package specification). These procedures Mark for Review
have no parameters. Which of the following package bodies will NOT compile (1) Points
successfully? (Choose two.)

(Choose all correct answers)

CREATE OR REPLACE PACKAGE BODY forward_pack IS


PROCEDURE proc2 IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Any message');
END;
PROCEDURE proc1 IS
BEGIN
proc2;
END;
END forward_pack;
CREATE OR REPLACE PACKAGE BODY forward_pack IS
PROCEDURE proc1 IS
BEGIN
proc2;
END;
PROCEDURE proc2 IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Any message');
END;
END forward_pack;

(*)
CREATE OR REPLACE PACKAGE BODY forward_pack IS
PROCEDURE proc2;
PROCEDURE proc1 IS
BEGIN
proc2;
END;
PROCEDURE proc2 IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Any message');
END;
END forward_pack;
CREATE OR REPLACE PACKAGE BODY forward_pack IS
PROCEDURE proc2;
PROCEDURE proc1 IS
BEGIN
proc2;
END;
PROCEDURE proc2 IS
BEGIN
proc1;
END;
END forward_pack;
CREATE OR REPLACE PACKAGE BODY forward_pack IS
PROCEDURE proc1;
PROCEDURE proc1 IS
BEGIN
proc2;
END;
PROCEDURE proc2 IS
proc1;
END;
END forward_pack;

(*)

Incorrect. Refer to Section 10 Lesson 3.

13. Functions called from a SQL query or DML statement must not end the current
transaction, or create or roll back to a savepoint. True or False? Mark for Review
(1) Points

True (*)
False

Correct

14. Which two of these functions could not be in the same package?
Mark for Review
1. FUNCTION get_emp (p1 DATE) RETURN VARCHAR2; (1) Points
2. FUNCTION get_emp (p1 DATE, p2 NUMBER) RETURN VARCHAR2;
3. FUNCTION get_emp (p1 DATE, p2 NUMBER) RETURN NUMBER;
4. FUNCTION get_emp (p1 NUMBER, p2 DATE) RETURN VARCHAR2;

2 and 3 (*)
1 and 4
2 and 4
1 and 2
3 and 4

Correct

15. A public function in a package is invoked from within a SQL statement. The
function's code can include a COMMIT statement. True or False? Mark for Review
(1) Points

True
False (*)
Incorrect. Refer to Section 10 Lesson 3.

Section 11 Quiz
(Answer all questions in this section)

1. Which DBMS_OUTPUT package subprogram places text into the buffer at Line 1?
(Choose one) Mark for Review
(1) Points
IF v_bool1 AND NOT v_bool2 AND v_number < 25 THEN
--Line 1
ELSE
...
END IF;
DBMS_OUTPUT.NEW_LINE;

DBMS_OUTPUT.NEW_LINE('IF branch was executed');


DBMS_OUTPUT.PUT_LINE('IF branch was executed');
DBMS_OUTPUT.PUT('IF branch was executed'); (*)
DBMS_OUTPUT.GET_LINE('IF branch was executed');

Incorrect. Refer to Section 11 Lesson 2.

2. Which of the following procedures is not valid for the UTL_MAIL package
Mark for Review
(1) Points

SEND_ATTACH_RAW
SEND_ATTACH_VARCHAR2
SEND
SEND_ATTACH_BOOLEAN (*)
All are valid.

Incorrect. Refer to Section 11 Lesson 2.

3. Which general exceptions may be handled by the UTL_FILE package? (Choose 2)


Mark for Review
(1) Points

(Choose all correct answers)

ZERO_DIVIDE
VALUE_ERROR (*)
NO_DATA_FOUND (*)
TOO_MANY_ROWS

Incorrect. Refer to Section 11 Lesson 2.

4. The DBMS_OUTPUT package is useful for which of the following activities? (Choose
two) Mark for Review
(1) Points

(Choose all correct answers)

Trace the code execution path for a function or procedure (*)


Interact with a user during execution of a function or procedure
Display results to the developer during testing for debugging purposes (*)
Write operating system text files to the user's screen

Incorrect. Refer to Section 11 Lesson 2.

5. The DBMS_OUTPUT gives programmers an easy-to-use interface to see, for instance,


the current value of a loop counter, or whether or not a program reaches a particular Mark for Review
branch of an IF statement. (True or False?) (1) Points

True (*)
False

Correct

6. The
UTL_FILE Mark for Review
package (1) Points
can be
used to
create
binary
files such
as JPEGs
as well
as text
files.
True or
False?

True
False (*)

Incorrect. Refer to Section 11 Lesson 2.


7. The SEND procedure is for sending messages without attachments. True or
False? Mark for Review
(1) Points

True (*)
False

Correct

8. The UTL_FILE package contains several exceptions exclusively used in this


package. Which are they? (Choose 3) Mark for Review
(1) Points

(Choose all correct answers)

INVALID_PATH (*)
WRITE_ERROR (*)
INVALID_OPERATION (*)
NO_DATA_FOUND
ZERO_DIVIDE

Correct

9. DBMS_OUTPUT.PUT_LINE can be invoked from inside a private packaged


function. True or False? Mark for Review
(1) Points

True (*)
False

Correct

10. Using the FOPEN function, you can do which actions with the UTL_FILE package?
(Choose 2) Mark for Review
(1) Points

(Choose all correct answers)

It is used to append to a file until processing is complete. (*)


It is used to read and write text files stored outside the database. (*)
It is used to manipulate large object data type items in columns.
It is used to find out how much free space is left on an operating system
disk.
Correct

11. When a
user Mark for Review
session (1) Points
changes
the value of
a package
variable,
the new
value can
immediately
be seen by
other
sessions.
True or
False?

True
False (*)

Incorrect. Refer to Section 11 Lesson 1.

12. A cursor's state is defined only by whether it is open or closed and, if open,
how many rows it holds. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 11 Lesson 1.

13. A package's state is initialized when the package is first loaded. True or
False? Mark for Review
(1) Points

True (*)
False

Correct

14. In the following example, which statement best fits in Line 1? (Choose 1)
Mark for Review
DECLARE (1) Points
v_more_rows_exist BOOLEAN := TRUE;
BEGIN
-- Line 1
LOOP
v_more_rows_exist := curs_pkg.fetch_n_rows(3);
DBMS_OUTPUT.PUT_LINE('-------');
EXIT WHEN NOT v_more_rows_exist;
END LOOP;
curs_pkg.close_curs;
END;

curs_pkg.close_curs;
curs_pkg.emp_curs%ISOPEN;
curs_pkg.open_curs; (*)
EXIT WHEN curs_pkg.emp_curs%NOTFOUND;

Incorrect. Refer to Section 11 Lesson 1.

15. Package MULTIPACK declares the following global variable:


g_myvar NUMBER; Mark for Review
(1) Points
User DICK executes the following:
multipack.g_myvar := 45;

User HAZEL now connects to the database. Both users immediately execute:

BEGIN
DBMS_OUTPUT.PUT_LINE(multipack.g_myvar);
END;

What values will Dick and Hazel see?

Dick: 45, Hazel: 0


Dick: 45, Hazel: 45
Dick: 0, Hazel: 0
Dick: 45, Hazel: null (*)
Both queries will fail because the syntax of DBMS_OUTPUT.PUT_LINE is
incorrect

Incorrect. Refer to Section 11 Lesson 1.

1. Which of
the Mark for Review
following (1) Points
procedures
is not valid
for the
UTL_MAIL
package

SEND_ATTACH_RAW
SEND_ATTACH_BOOLEAN (*)
SEND
All are valid.
SEND_ATTACH_VARCHAR2

Incorrect. Refer to Section 11 Lesson 2.

2. Using the FOPEN function, you can do which actions with the UTL_FILE
package? (Choose 2) Mark for Review
(1) Points

(Choose all correct answers)

It is used to read and write text files stored outside the database. (*)
It is used to append to a file until processing is complete. (*)
It is used to manipulate large object data type items in columns.
It is used to find out how much free space is left on an operating system
disk.

Correct

3. Which of the following best describes the purpose of the UTL_FILE package?
Mark for Review
(1) Points

It is used to load binary files such as employees' photos into the database.
It is used to query CHAR and VARCHAR2 columns in tables.
It is used to read and write text files stored outside the database. (*)
It is used to find out how much free space is left on an operating system
disk.

Incorrect. Refer to Section 11 Lesson 2.

4. Which general exceptions may be handled by the UTL_FILE package? (Choose


2) Mark for Review
(1) Points

(Choose all correct answers)

VALUE_ERROR (*)
ZERO_DIVIDE
NO_DATA_FOUND (*)
TOO_MANY_ROWS
Incorrect. Refer to Section 11 Lesson 2.

5. The DBMS_OUTPUT gives programmers an easy-to-use interface to see, for


instance, the current value of a loop counter, or whether or not a program Mark for Review
reaches a particular branch of an IF statement. (True or False?) (1) Points

True (*)
False

Correct

6. The
UTL_FILE Mark for Review
package (1) Points
contains
several
exceptions
exclusively
used in
this
package.
Which are
they?
(Choose
3)

(Choose all correct answers)

ZERO_DIVIDE
WRITE_ERROR (*)
INVALID_OPERATION (*)
NO_DATA_FOUND
INVALID_PATH (*)

Correct

7. The DBMS_OUTPUT package is useful for which of the following activities?


(Choose two) Mark for Review
(1) Points

(Choose all correct answers)

Trace the code execution path for a function or procedure (*)


Interact with a user during execution of a function or procedure
Display results to the developer during testing for debugging purposes (*)
Write operating system text files to the user's screen
Incorrect. Refer to Section 11 Lesson 2.

8. Why is it better to use DBMS_OUTPUT only in anonymous blocks, not inside


stored subprograms such as procedures? Mark for Review
(1) Points

Because DBMS_OUTPUT should be used only for testing and debugging


PL/SQL code (*)
Because DBMS_OUTPUT can raise a NO_DATA_FOUND exception if used
inside a packaged procedure
Because DBMS_OUTPUT cannot be used inside procedures
Because anonymous blocks display messages while the block is executing,
while procedures do not display anything until their execution has finished

Correct

9. What will be displayed when the following code is executed?


Mark for Review
BEGIN (1) Points
DBMS_OUTPUT.PUT('I do like');
DBMS_OUTPUT.PUT_LINE('to be');
DBMS_OUTPUT.PUT('beside the seaside');
END;

I do like to be
I do like to be beside the seaside
I do like to be
beside the seaside
I do liketo be

(*)
I do like
to be
beside the seaside

Incorrect. Refer to Section 11 Lesson 2.

10. DBMS_OUTPUT.PUT_LINE can be invoked from inside a private packaged


function. True or False? Mark for Review
(1) Points

True (*)
False

Correct
11. A
package's Mark for Review
state is (1) Points
initialized
when the
package
is first
loaded.
True or
False?

True (*)
False

Correct

12. A cursor is declared in a package specification. User SIOBHAN opens the cursor
and fetches the first three rows from the cursor's active set, but does not close Mark for Review
the cursor. (1) Points
User FRED now connects to the database. FRED can immediately fetch the next
three rows without opening the cursor. True or False?

True
False (*)

Incorrect. Refer to Section 11 Lesson 1.

13. Users A and B call the same procedure in a package to initialize a global
variable my_pkg.g_var. What will be the value of my_pkg.g_var for User A at Mark for Review
Point A? (1) Points

User A: my_pkg.g_var is 10
User B: my_pkg.g_var is 10
User A: my_pkg.g_var is 50
User B: my_pkg.g_var is 25
Point A

50 (*)
25
10

Correct

14. When a user session changes the value of a package variable, the new value
can immediately be seen by other sessions. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 11 Lesson 1.

15. Package CURSPACK declares a global cursor in the package specification. The
package contains three public procedures: OPENPROC opens the cursor; Mark for Review
FETCHPROC fetches 5 rows from the cursor's active set; CLOSEPROC closes the (1) Points
cursor.

What will happen when a user session executes the following commands in the
order shown?
curspack.openproc; -- line 1
curspack.fetchproc; -- line 2
curspack.fetchproc; -- line 3
curspack.openproc; -- line 4
curspack.fetchproc; -- line 5
curspack.closeproc; -- line 6

The first 15 rows will be fetched.


An error will occur at line 4. (*)
The first 5 rows will be fetched three times.
An error will occur at line 2.
The first 10 rows will be fetched, then the first 5 rows will be fetched
again.

Incorrect. Refer to Section 11 Lesson 1.

Section 12 Quiz
(Answer all questions in this section)

1. Name two reasons for using Dynamic SQL.


Mark for Review
(1) Points

(Choose all correct answers)

Provides the ability to execute SQL statements whose structure is unknown until
execution time. (*)
Provides the ability to handle mutating rows when executing a statement involving
the same table.
Enables session-control statements to be written and executed from PL/SQL. (*)
Allows fetch of data for DML statements.

Incorrect. Refer to Section 12 Lesson 1.

2. The following procedure adds a column of datatype DATE to the EMPLOYEES table. The
name of the new column is passed to the procedure as a parameter. Mark for Review
(1) Points
CREATE OR REPLACE PROCEDURE addcol
(p_col_name IN VARCHAR2) IS
v_first_string VARCHAR2(100) := 'ALTER TABLE EMPLOYEES ADD (';
v_second_string VARCHAR2(6) := ' DATE)';
BEGIN
... Line A
END;

Which of the following will work correctly when coded at line A? (Choose two.)

(Choose all correct answers)

EXECUTE IMMEDIATE v_first_string || p_col_name || v_second_string;

(*)
EXECUTE v_first_string || p_col_name || v_second_string;
EXECUTE IMMEDIATE 'v_first_string' || p_col_name || 'v_second_string';
v_first_string := v_first_string || p_col_name;
EXECUTE IMMEDIATE v_first_string || v_second_string;

(*)
v_first_string || p_col_name || v_second_string;

Incorrect. Refer to Section 12 Lesson 1.

3. Dynamic SQL enables data-definition, data-control, or session-control statements to be


written and executed from PL/SQL. Mark for Review
(1) Points

True (*)
False

Correct

4. The DBMS_SQL package is easier to use than EXECUTE IMMEDIATE. True or False?
Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 12 Lesson 1.

5. When SQL statements are included within a procedure, the statements are parsed
when the procedure is compiled. True or False? Mark for Review
(1) Points
True (*)
False

Correct

6. Which of
the Mark for Review
following (1) Points
SQL
statements
can be
included in
a PL/SQL
block only
by using
Dynamic
SQL?
(Choose
two.)

(Choose all correct answers)

SELECT ..... FOR UPDATE NOWAIT


ALTER (*)
GRANT (*)
SAVEPOINT
DELETE

Incorrect. Refer to Section 12 Lesson 1.

7. A public packaged procedure contains the following SQL statement:


UPDATE employees Mark for Review
SET salary = salary * 1.1; (1) Points
When is this SQL statement parsed?

When the package specification is created


When the package body is created (*)
Only the first time the procedure is executed
When the package is loaded into memory
When the package header is loaded into memory

Incorrect. Refer to Section 12 Lesson 1.


8. FORALL can be used with any DML statement. True or False?
Mark for Review
(1) Points

True (*)
False

Correct

9. In the following example, where do you place the phrase DETERMINISTIC?


Mark for Review
CREATE OR REPLACE FUNCTION total_sal (1) Points
(p_dept_id IN -- Position A
employees.department_id%TYPE)
RETURN NUMBER -- Position B
IS v_total_sal NUMBER;
BEGIN
SELECT SUM(salary) INTO v_total_sal
FROM employees WHERE department_id = p_dept_in;
RETURN v_total_sal -- Position C;
END total_sal;

Position A
Position B (*)
Position C

Incorrect. Refer to Section 12 Lesson 2.

10. You want to take make a copy of all the cities in the world listed in the cities
table, which contains millions of rows. The following procedure accomplishes Mark for Review
this efficiently. True or False? (1) Points

CREATE OR REPLACE PROCEDURE copy_cities IS


TYPE t_cities IS TABLE OF cities%ROWTYPE INDEX BY BINARY_INTEGER;
v_citiestab t_emp;
BEGIN
SELECT * BULK COLLECT INTO v_citiestab FROM cities;
FORALL i IN v_citiestab.FIRST..v_citiestab.LAST
INSERT INTO new_cities VALUES v_citiestab(i);
END copy_cities;

True (*)
False

Correct

11. The following statement is a


valid example of using the Mark for Review
(1) Points
RETURNING clause. True or
False?

DECLARE
TYPE EmpRec IS RECORD
(last_name
employees.last_name%TYPE,
salary
employees.salary%TYPE);
emp_info EmpRec;
emp_id NUMBER := 100;
BEGIN
UPDATE employees
SET salary = salary * 1.1
WHERE employee_id =
emp_id;
RETURNING last_name,
salary INTO emp_info;
dbms_output.put_line('Just
gave a raise to ' ||
emp_info.last_name ||
', who now makes ' ||
emp_info.salary);
END;

True (*)
False

Correct

12. In the following example, where do you place the phrase


BULK COLLECT? Mark for Review
(1) Points
...
BEGIN
SELECT -- Position A
salary -- Position B
INTO v_saltab -- Position C
FROM employees WHERE department_id = 20 ORDER
BY salary
-- Position D
;
...

Position A
Position B (*)
Position C
Position D

Incorrect. Refer to Section 12


Lesson 2.
13. The following example code will compile successfully. True
or False? Mark for Review
(1) Points
CREATE OR REPLACE PROCEDURE dept_proc IS
TYPE t_dept IS TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;
BEGIN
(p_small_arg IN NUMBER, p_big_arg OUT NOCOPY
t_dept);
-- remaining code
END dept_proc;

True (*)
False

Correct

14. What is wrong with this code example?


Mark for Review
CREATE OR REPLACE PROCEDURE insert_emps IS (1) Points
TYPE t_emp IS TABLE OF employees%ROWTYPE INDEX
BY BINARY_INTEGER;
v_emptab t_emp;
BEGIN
FORALL i IN v_emptab.FIRST..v_emptab.LAST
INSERT INTO employees VALUES v_emptab(i);
END LOOP;
END insert_emps;

Nothing is wrong; it will compile successfully.


The phrase should be FOR ALL.
v_emptab is incorrectly typed.
FORALL does not require END LOOP. (*)

Incorrect. Refer to Section 12


Lesson 2.

15. Deterministic means the function will always return the


same output return value for any given set of input Mark for Review
argument values. True or False? (1) Points

True (*)
False

Correct
1. A SQL
statement Mark for Review
can pass (1) Points
through
several
stages.
Which of
the
following
is NOT
one of
these
stages?

BIND
EXECUTE
FETCH
PARSE
RETURN (*)

Incorrect. Refer to Section 12 Lesson 1.

2. Only one call to DBMS_SQL is needed in order to drop a table. True or False?
Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 12 Lesson 1.

3. You want to create a function which drops a table. You write the following code:
Mark for Review
CREATE OR REPLACE FUNCTION droptab (1) Points
(p_tab_name IN VARCHAR2)
RETURN BOOLEAN IS
BEGIN
DROP TABLE p_tab_name;
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN RETURN FALSE;
END;

Why will this procedure not compile successfully?

Because you do not have the privilege needed to drop a table


Because you can never drop a table from inside a function
Because the PL/SQL compiler cannot check if the argument of p_tab_name
is a valid table-name (*)
Because you cannot use RETURN in the exception section

Incorrect. Refer to Section 12 Lesson 1.

4. What will happen when the following procedure is invoked?


Mark for Review
CREATE OR REPLACE PROCEDURE do_some_work IS (1) Points
CURSOR c_curs IS SELECT object_name FROM user_objects
WHERE object_type = 'FUNCTION';
BEGIN
FOR v_curs_rec IN c_curs LOOP
EXECUTE IMMEDIATE 'ALTER FUNCTION ' || v_curs_rec.object_name || '
COMPILE';

EXIT WHEN c_curs%ROWCOUNT > 2;


END LOOP;
END;

All functions in the user's schema will be recompiled.


The first two functions in the user's schema will be recompiled.
The procedure will not compile successfully because the syntax of the
ALTER FUNCTION statement is incorrect.
The procedure will not compile successfully because you cannot ALTER
functions using Dynamic SQL.
The first three functions in the user's schema will be recompiled. (*)

Incorrect. Refer to Section 12 Lesson 1.

5. Dynamic SQL enables data-definition, data-control, or session-control statements


to be written and executed from PL/SQL. Mark for Review
(1) Points

True (*)
False

Correct

6. The
easiest Mark for Review
way to (1) Points
include
DDL
statements
in a
PL/SQL
block is to
use the
DBMS_SQL
package.
True or
False?

True
False (*)

Incorrect. Refer to Section 12 Lesson 1.

7. Which is the correct order for the execution flow of SQL?


Mark for Review
(1) Points

Parse
Bind
Execute
Fetch
(*)
Execute
Parse
Fetch
Bind
Bind
Parse
Execute
Fetch
Parse
Fetch
Bind
Execute

Correct

8. FORALL can be used with any DML statement. True or False?


Mark for Review
(1) Points

True (*)
False

Correct

9. In the following example, where do you place the phrase BULK COLLECT?
Mark for Review
DECLARE (1) Points
TYPE NameList IS TABLE OF emp.ename%TYPE;
names NameList;
CURSOR c1 IS SELECT ename -- Position A
FROM emp WHERE job = 'CLERK';
BEGIN
OPEN c1;
FETCH c1 -- Position B
INTO -- Position C
names;
...
CLOSE c1;
END;

Position A
Position B (*)
Position C

Incorrect. Refer to Section 12 Lesson 2.

10. Deterministic means the function will always return the same output return
value for any given set of input argument values. True or False? Mark for Review
(1) Points

True (*)
False

Correct

11. What is the correct syntax to


use the RETURNING phrase Mark for Review
at Position A? (1) Points

DECLARE
TYPE EmpRec IS RECORD
(last_name
employees.last_name%TYPE,
salary
employees.salary%TYPE);
emp_info EmpRec;
emp_id NUMBER := 100;
BEGIN
UPDATE employees
SET salary = salary * 1.1
WHERE employee_id =
emp_id
-- Position A
dbms_output.put_line('Just
gave a raise to ' ||
emp_info.last_name || ', who
now makes ' ||
emp_info.salary);
END;

last_name, salary RETURNING INTO emp_info;


RETURNING last_name, salary INTO emp_info; (*)
RETURNING FROM emp_info;
RETURNING last_name, salary TO emp_info;

Incorrect. Refer to Section 12


Lesson 2.

12. To create a list of the top 20 movies from a catalog of


millions of titles, the following statement grabs those rows Mark for Review
using a collection. True or False? (1) Points

...
TYPE nametab IS TABLE OF movies.title%TYPE;
Title_tab nametab;
...
SELECT title BULK COLLECT INTO title_tab FROM movies
ORDER BY rental_count DESC;
...

True (*)
False

Correct

13. In the following example, where do you place the phrase


DETERMINISTIC? Mark for Review
(1) Points
CREATE OR REPLACE FUNCTION total_sal
(p_dept_id IN -- Position A
employees.department_id%TYPE)
RETURN NUMBER -- Position B
IS v_total_sal NUMBER;
BEGIN
SELECT SUM(salary) INTO v_total_sal
FROM employees WHERE department_id = p_dept_in;
RETURN v_total_sal -- Position C;
END total_sal;

Position A
Position B (*)
Position C

Incorrect. Refer to Section 12


Lesson 2.

14. The following example code will compile successfully. True


or False? Mark for Review
(1) Points
CREATE OR REPLACE PROCEDURE dept_proc IS
TYPE t_dept IS TABLE OF departments%ROWTYPE INDEX
BY BINARY_INTEGER;
BEGIN
(p_small_arg IN NUMBER, p_big_arg OUT NOCOPY
t_dept);
-- remaining code
END dept_proc;

True (*)
False

Correct

15. The following procedure compiles successfully. True or


False? Mark for Review
(1) Points
CREATE OR REPLACE PACKAGE emp_pkg IS
TYPE t_emp IS TABLE OF employees%ROWTYPE
INDEX BY BINARY_INTEGER;
PROCEDURE emp_proc
(p_small_arg IN NUMBER, p_big_arg NOCOPY OUT
t_emp);
...
END emp_pkg;

True
False (*)

Incorrect. Refer to Section 12


Lesson 2.

Section 13 Quiz
(Answer all questions in this section)

1. What is the purpose of using the CALL statement in a trigger?


Mark for Review
(1) Points

It allows the trigger body code to be placed in a separate procedure. (*)


It allows the trigger body code to be placed in a separate trigger.
It prevents cascading triggers.
It allows both DML events and DDL events to be handled using a single trigger.
It allows an INSTEAD OF trigger to be a statement trigger.

Correct

2. What is the benefit of using the CALL statement in a trigger body?


Mark for Review
(1) Points
It allows the database administrator to monitor who is currently connected to the
database.
It allows the trigger body code to be placed in a separate procedure. (*)
It allow both DDL events and database events to be handled by a single trigger.
It prevents data being read from a mutating table.

Incorrect. Refer to Section 13 Lesson 4.

3. The database administrator creates a trigger that automatically disconnects user


HACKER whenever HACKER connects to the database. What type of trigger is this? Mark for Review
(1) Points

An INSTEAD OF trigger
A DML trigger
A DDL trigger
A statement trigger
A Database Event trigger (*)

Incorrect. Refer to Section 13 Lesson 4.

4. Which of the following are good guidelines to follow when creating a database trigger?
(Choose two.) Mark for Review
(1) Points

(Choose all correct answers)

Do not create a trigger that automatically fires another trigger. (*)


Use triggers to override privilege checking and view other users' private tables.
Where possible, use a trigger to enforce a foreign key constraint.
Use triggers to prevent unauthorized users from SELECTing confidential data.
Do not use a trigger to replace or duplicate something which the Oracle Server
does automatically. (*)

Incorrect. Refer to Section 13 Lesson 1.

5. A business rule states that an employee's salary must be between 4000 and 30000. We
could enforce this rule using a check constraint, but it is better to use a database Mark for Review
trigger. True or False? (1) Points

True
False (*)

Incorrect. Refer to Section 13 Lesson 1.


6. Which of
the Mark for Review
following (1) Points
are good
guidelines
to follow
when
creating
triggers?
(Choose
two)

(Choose all correct answers)

Avoid lengthy trigger logic by creating a procedure and invoking it from


within the trigger (*)
Be aware of recursive and cascading effects (*)
Use triggers to replace functionality which is already built into the database
Where possible, use triggers to enforce NOT NULL constraints
Always create more triggers than you need, because it is better to be safe

Correct

7. User KULJIT creates two triggers named EMP1_TRIGG and EMP2_TRIGG, which
are both DML triggers referencing her EMPLOYEES table. Kuljit now wants to Mark for Review
remove both of these triggers from the database. What command(s) should (1) Points
Kuljit use to do this?

DROP TRIGGER emp1_trigg;


DROP TRIGGER emp2_trigg;

(*)
DROP ALL TRIGGERS ON employees;
DROP TRIGGER emp1_trigg AND emp2_trigg;
DROP TRIGGERS ON employees;

Correct

8. You need to disable all triggers that are associated with DML statements on the
DEPARTMENTS table. Which of the following commands should you use? Mark for Review
(1) Points

ALTER TABLE departments DROP ALL TRIGGERS;


ALTER TRIGGER DISABLE ALL ON departments;
ALTER TABLE departments DISABLE ALL TRIGGERS; (*)
ALTER TABLE departments DISABLE TRIGGERS;
DISABLE ALL TRIGGERS ON departments;
Incorrect. Refer to Section 13 Lesson 5.

9. After the following SQL statement is executed, all the triggers on the
DEPARTMENTS table will no longer fire, but will remain in the database. True or Mark for Review
False? (1) Points

ALTER TABLE departments DISABLE ALL TRIGGERS;

True (*)
False

Correct

10. The following view and trigger have been created:


Mark for Review
CREATE VIEW dept_view AS SELECT * FROM departments; (1) Points
CREATE OR REPLACE TRIGGER dept_view_trigg
INSTEAD OF UPDATE ON dept_view
BEGIN
DBMS_OUTPUT.PUT_LINE('Sample Message');
END;

Departments 50 and 80 exist but department 81 does not. A user now executes
the following statement:

UPDATE dept_view SET department_name = 'Sales'


WHERE department_id IN (50,80,81);

What happens?

Two rows are updated and "Sample Message" is displayed once.


No rows are updated and "Sample Message" is displayed three times.
No rows are updated and "Sample Message" is displayed twice. (*)
None of these.
No rows are updated and "Sample Message" is displayed once.

Incorrect. Refer to Section 13 Lesson 3.

11. There are 3


employees in Mark for Review
department 90 (1) Points
and 5
employees in
department 50.
The following
trigger has
been created:
CREATE
TRIGGER
upd_emp_trigg
AFTER UPDATE
ON employees
FOR EACH
ROW
BEGIN
...

A user now
executes:

UPDATE
employees
SET
department_id
= 50
WHERE
department_id
= 90;

How many
times will the
trigger fire?

Once
Three times (*)
Four times
Five times
Eight times

Incorrect. Refer to Section 13 Lesson 3.

12. Which of the following can NOT be coded in the body of a DML trigger?
(Choose two.) Mark for Review
(1) Points

(Choose all correct answers)

IF OTHERS THEN (*)


IF INSERTING THEN
IF UPDATING ('JOB_ID') THEN
IF DELETING THEN
IF SELECTING THEN (*)

Incorrect. Refer to Section 13 Lesson 3.


13. There are five employees in department 50. A statement trigger is
created by: Mark for Review
(1) Points
CREATE OR REPLACE TRIGGER emp_upd_trigg
AFTER DELETE ON EMPLOYEES
BEGIN ...

A user now executes:


DELETE FROM employees WHERE department_id = 50;

How many times will the trigger fire, and when?

The trigger will not fire at all.


Once, after the DELETE is executed (*)
Once, before the DELETE is executed
Five times, after each employee row is deleted
Six times, once after each row and once at the end of the statement

Incorrect. Refer to Section 13 Lesson 2.

14. An AFTER UPDATE trigger can specify more than one column. True or
False? Mark for Review
(1) Points

True (*)
False

Correct

15. The following code will successfully create emp_trigg: True or False?
Mark for Review
CREATE OR REPLACE TRIGGER emp_trigg (1) Points
BEFORE DELETE OF salary ON employees
BEGIN
RAISE_APPLICATION_ERROR(-20202,'Deleting salary is not allowed');
END;

True
False (*)

Incorrect. Refer to Section 13 Lesson 2.

1. Which
command Mark for Review
would (1) Points
you use
to see if
your
triggers
are
enabled
or
disabled?

DESCRIBE TRIGGER
SELECT trigger_name, trigger_type
FROM USER_TRIGGERS;
SELECT trigger_name, status
FROM USER_TRIGGERS;

(*)
SELECT object_name, status
FROM USER_OBJECTS
WHERE object_type = 'TRIGGER';

Incorrect. Refer to Section 13 Lesson 5.

2. User AYSEGUL successfully creates the following trigger:


Mark for Review
CREATE TRIGGER loc_trigg (1) Points
BEFORE UPDATE ON aysegul.locations
BEGIN ....

AYSEGUL now tries to drop the LOCATIONS table. What happens?

Both the table and the trigger are dropped. (*)


An error message is displayed because you cannot drop a table that is
associated with a trigger.
The trigger is dropped but the table is not dropped.
The table is dropped and the trigger is disabled.
None of these.

Correct

3. You have created several DML triggers which reference your DEPARTMENTS
table. Now you want to disable all of them using a single SQL statement. Which Mark for Review
command should you use? (1) Points

ALTER TRIGGER DISABLE ALL ON departments;


ALTER TABLE departments DISABLE ALL TRIGGERS; (*)
ALTER TABLE departments DISABLE TRIGGERS;
DROP ALL TRIGGERS ON departments;

Incorrect. Refer to Section 13 Lesson 5.


4. The OLD and NEW qualifiers can be used with statement triggers as well as row
triggers. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 13 Lesson 3.

5. What is wrong with the following code example for a compound trigger?
Mark for Review
CREATE OR REPLACE TRIGGER log_emps (1) Points
FOR UPDATE OF salary ON employees
COMPOUND TRIGGER
TYPE t_log_emp IS TABLE OF log_table%ROWTYPE
INDEX BY BINARY_INTEGER;
log_emp_tab t_log_emp;

AFTER EACH ROW IS


BEGIN
-- some action
END AFTER EACH ROW;

AFTER STATEMENT IS
BEGIN
-- some action
END AFTER STATEMENT;
END log_emps;

There is nothing wrong with this example.


The triggering event FOR UPDATE is not allowed.
The COMPOUND TRIGGER statement is missing IS.
The declaration section is missing the DECLARE keyword. (*)
The order of the timing statements is reversed.

Incorrect. Refer to Section 13 Lesson 3.

6. What are the


components of a Mark for Review
compound trigger? (1) Points

Declaration
section and at
least one
timing
section. (*)
Declaration
section,
referencing
section, and
timing
sections.
Declaration
section and at
least two
timing
sections.
Declaration
section and all
four timing
sections.
Declaration
section,
timing
sections, and
exception
section.

Correct

7. While editing a
document in Mark for Review
Microsoft Word, (1) Points
you go to the FILE
menu and SAVE
your work. To do
this, Microsoft
Word has executed
an application
trigger. True or
False?

True (*)
False

Correct

8. Which of the
following best Mark for Review
describes a (1) Points
database trigger?

A subprogram
that checks
whether a
user has
typed the
correct
password to
log on to the
database
A subprogram
that is
invoked
explicitly by
the calling
application
A PL/SQL
subprogram
that executes
automatically
whenever an
associated
database
event occurs
(*)
A PL/SQL
subprogram
that always
returns
exactly one
value
A PL/SQL
subprogram
that inserts
rows into a
logging table

Incorrect.
Refer to
Section 13
Lesson 1.

9. What type of
database object Mark for Review
would you create (1) Points
to write an auditing
record
automatically every
time a user
connects to the
database?

A function
A complex
view
A trigger (*)
A package
A procedure

Incorrect.
Refer to
Section 13
Lesson 1.
10. There are five
employees in Mark for Review
department 50. (1) Points
The following
trigger is created:

CREATE TRIGGER
upd_emp
AFTER UPDATE ON
employees
BEGIN
INSERT INTO
audit_table
VALUES (USER,
SYSDATE);
END;

A user now
executes:

UPDATE
employees
SET salary = salary
* 1.1
WHERE
department_id =
50;

How many rows


will be inserted into
audit_table?

One (*)
Two
Five
Six
None of
these.

Correct

11. An
AFTER Mark for Review
UPDATE (1) Points
trigger
can
specify
more
than
one
column.
True or
False?

True (*)
False

Correct

12. What is wrong with the following code?


Mark for Review
CREATE OR REPLACE TRIGGER emp_dept_trigg (1) Points
BEFORE UPDATE OR DELETE ON employees, departments
BEGIN
...

DML triggers must be row triggers, so FOR EACH ROW is missing


The second line should be:
BEFORE UPDATE OR DELETE ON employees OR departments
The second line should be:
BEFORE (UPDATE,DELETE) ON employees, departments
One trigger can be associated with only one table

(*)

Incorrect. Refer to Section 13 Lesson 2.

13. You want to prevent any objects in your schema from being altered or dropped.
You decide to create the following trigger: Mark for Review
(1) Points
CREATE TRIGGER stop_ad_trigg
-- Line A
BEGIN
RAISE_APPLICATION_ERROR(-20203,'Invalid Operation');
END;

What should you code at Line A ?

AFTER ALTER OR DROP ON SCHEMA


BEFORE ALTER, DROP ON SCHEMA
AFTER ALTER, DROP ON SCHEMA
BEFORE ALTER OR DROP ON SCHEMA (*)
INSTEAD OF ALTER OR DROP ON SCHEMA

Incorrect. Refer to Section 13 Lesson 4.

14. What is the benefit of using the CALL statement in a trigger body?
Mark for Review
(1) Points
It allow both DDL events and database events to be handled by a single
trigger.
It allows the database administrator to monitor who is currently connected
to the database.
It prevents data being read from a mutating table.
It allows the trigger body code to be placed in a separate procedure. (*)

Incorrect. Refer to Section 13 Lesson 4.

15. The database administrator creates a trigger that automatically disconnects user
HACKER whenever HACKER connects to the database. What type of trigger is Mark for Review
this? (1) Points

A DML trigger
An INSTEAD OF trigger
A Database Event trigger (*)
A DDL trigger
A statement trigger

Incorrect. Refer to Section 13 Lesson 4.

Section 14 Quiz
(Answer all questions in this section)

1. Which statement for setting a database parameter is the default for remote
dependency checking? Mark for Review
(1) Points

ALTER SESSION REMOTE_DEPENDENCIES_MODE = SIGNATURE


ALTER SESSION SET REMOTE_DEPENDENCIES_MODE = TIMESTAMP (*)
ALTER SESSION SET REMOTE_DEPENDENCIES_MODE = SIGNATURE
ALTER SESSION REMOTE_DEPENDENCIES_MODE = TIMESTAMP

Incorrect. Refer to Section 14 Lesson 2.

2. Which is not a
mode that can Mark for Review
be used to (1) Points
determine the
dependency
status of
schema
objects when
dealing with
remote
dependencies?

Time Stamp Mode


All of these are valid.
Time Mode (*)
Signature Mode

Incorrect. Refer to Section 14 Lesson 2.

3. With remote
dependencies, Mark for Review
which of the (1) Points
following is
True?

There is one master data dictionary that resides on one server which identifies the status of
all schema objects.
The dependency status is not recorded.
There are two separate data dictionaries on two different servers. (*)

Incorrect. Refer to Section 14 Lesson 2.

4. A change in a
remote Mark for Review
referenced (1) Points
subprogram is
automatically
recorded as
invalid if its
base object
changes and
that new
status is
relayed to the
dependent
object's status
and
automatically
marked as
invalid. True or
False?

True
False (*)
Incorrect.
Refer to
Section
14
Lesson 2.

5. In this
scenario, Mark for Review
the (1) Points
following
status is
given for
each
procedure:

- Procedure
A is local
and has a
time stamp
of 10 AM
- Procedure
B is remote
and has a
local time
stamp of 5
AM and has
a remote
time stamp
of 4 AM

In
Timestamp
Mode,
Procedure
A will
execute
successfully
at 11 AM.
True or
False?

True
False (*)

Incorrect. Refer to Section 14 Lesson 2.

6. Which of the
following will Mark for Review
display (1) Points
dependency
information
which has
been
generated by
executing the
DEPTREE_FILL
procedure?
(Choose two.)

(Choose all correct answers)

The DEPTREE view (*)


The DISPLAY_DEPTREE view
The USER_DEPENDENCIES view
The IDEPTREE view (*)
The UTLDTREE script

Incorrect. Refer to Section 14 Lesson 1.

7. Which data
dictionary Mark for Review
view shows (1) Points
information
about
references
and
dependencies?

DEPTREE
USER_LOCAL_DEPENDENCIES
USER_DEPENDENCIES (*)
USER_REFERENCES

Incorrect. Refer to Section 14 Lesson 1.

8. A
procedure Mark for Review
includes the (1) Points
following
code:

CURSOR
loc_curs IS
SELECT
location_id,
city,
country_id
FROM
locations;

Which of
the
following
changes to
the
LOCATIONS
table will
allow the
procedure
to be
recompiled
successfully
without
editing its
code?
(Choose
two.)

(Choose all correct answers)

RENAME locations TO new_locations;


ALTER TABLE locations DROP COLUMN city;
ALTER TABLE locations DROP COLUMN postal_code; (*)
ALTER TABLE locations ADD (climate VARCHAR2(30)); (*)

Incorrect. Refer to Section 14 Lesson 1.

9. Which of
the Mark for Review
following (1) Points
will NOT
help to
minimize
dependency
failures?
(Choose
two.)

(Choose all correct answers)

Declaring scalar variables using the %TYPE attribute


Including a column list with INSERT statements
SELECTing a list of column names instead of using SELECT * (*)
Declaring records using the %ROWTYPE attribute
Declaring scalar variables with NOT NULL if the corresponding table column has a NOT NULL
constraint (*)
Incorrect. Refer to Section 14 Lesson 1.

10. PL/SQL
procedure Mark for Review
A invokes (1) Points
procedure
B, which in
turn
invokes
procedure
C, which
references
table T. If
table T is
dropped,
which of
the
following
statements
is true?

C is invalid but A and B are still valid


A, B and C are all still valid
B and C are invalid but A is still valid
None of these.
A, B and C are all invalid (*)

Incorrect. Refer to Section 14 Lesson 1.

11. The IDEPTREE


view shows Mark for Review
dependencies (1) Points
by indenting
the lines of
output instead
of by using a
NESTED_LEVEL
column. True
or False?

True (*)
False

Correct
12. A procedure
includes the Mark for Review
following (1) Points
code:

SELECT
first_name,
salary INTO
v_first_name,
v_salary
FROM
employees
WHERE
employee_id
= 100;

Which of the
following
changes to
the
employees
table will
allow the
procedure to
be
recompiled
successfully ?
(Choose
two.)

(Choose all correct answers)

The table is dropped but a public table exists with the same name and structure. (*)
The table is dropped.
The table name is changed to newemps.
A new column is added to the table. (*)
The first_name column is dropped from the table.

Incorrect. Refer to Section 14 Lesson 1.

13. When a
table is Mark for Review
dropped, all (1) Points
PL/SQL
subprograms
that
reference
the table are
automatically
dropped.
True or
False?
True
False (*)

Incorrect. Refer to Section 14 Lesson 1.

14. Which of
the Mark for Review
following (1) Points
database
objects are
created
when the
utldtree.sql
script is
run?
(Choose
three.)

(Choose all correct answers)

The deptree_fill procedure (*)


The deptree_temptab table (*)
The utldtree table
The deptree table
The deptree and ideptree views (*)

Incorrect. Refer to Section 14 Lesson 1.

15. User BOB wants to know which objects reference his


DEPARTMENTS table. Which of the following must Mark for Review
he execute to populate the DEPTREE_TEMPTAB (1) Points
table?

BEGIN
deptree_fill('TABLE','BOB','DEPARTMENTS');
END;

(*)
BEGIN
utldtree('DEPARTMENTS');
END;
BEGIN
ideptree('TABLE','BOB','DEPARTMENTS');
END;
BEGIN
deptree_fill('TABLE','DEPARTMENTS');
END;

Correct

1. Which of
the Mark for Review
following (1) Points
will NOT
help to
minimize
dependency
failures?
(Choose
two.)

(Choose all correct answers)

Declaring scalar variables using the %TYPE attribute


Including a column list with INSERT statements
SELECTing a list of column names instead of using SELECT * (*)
Declaring scalar variables with NOT NULL if the corresponding table column has a NOT NULL
constraint (*)
Declaring records using the %ROWTYPE attribute

Incorrect. Refer to Section 14 Lesson 1.

2. View
dept_view is Mark for Review
based on a (1) Points
select from
table
departments.
Procedure
show_dept
contains
code which
selects from
dept_view.
Which of the
following
statements
are true?
(Choose
three.)
(Choose all correct answers)

dept_view is directly dependent on departments (*)


show_dept is indirectly dependent on departments (*)
emp_view is directly dependent on show_dept
departments is indirectly dependent on show_dept
show_dept is directly dependent on dept_view (*)

Incorrect. Refer to Section 14 Lesson 1.

3. User ALICE
owns a Mark for Review
procedure (1) Points
show_emps
which
references
table
employees.
Which of the
following will
generate
information
that shows
this
dependency?

BEGIN deptree_fill('TABLE','ALICE','EMPLOYEES');
END;

(*)
BEGIN deptree_fill('ALICE','PROCEDURE','SHOW_EMPS');
END;
BEGIN deptree_fill('ALICE','TABLE','EMPLOYEES');
END;
BEGIN deptree_fill('PROCEDURE','ALICE','SHOW_EMPS');
END;
BEGIN deptree_fill('TABLE','EMPLOYEES');
END;

Correct

4. A procedure
show_emps Mark for Review
contains the (1) Points
following
declaration:
CURSOR
emp_curs
IS SELECT
last_name,
salary
FROM
employees;

What will
happen to
the
procedure if
a new
column is
added to
the
employees
table?

The procedure will still be valid and execute correctly because it does not reference the added
column.
The procedure will automatically be dropped and must be recreated.
The procedure will be marked invalid and must be recompiled before it can be reexecuted. (*)
Users' privileges to execute the procedure will automatically be revoked.

Incorrect. Refer to Section 14 Lesson 1.

5. Which of
the Mark for Review
following is (1) Points
NOT
created
when the
utldtree.sql
script is
run?

The DEPTREE view


The DEPTREE_TEMPTAB table
The USER_DEPENDENCIES view (*)
The DEPTREE_FILL procedure

Incorrect. Refer to Section 14 Lesson 1.

6. Package emp_pack
contains two public Mark for Review
procedures: (1) Points
get_emps and
upd_emps. A
separate procedure
emp_proc invokes
emp.pack.get_emps.
The upd_emps
package body code
is now altered, and
the package body
(but not the
package
specification) is
recreated.

emp_proc will be
marked invalid and
needs to be
recompiled. True or
False?

True
False (*)

Incorrect. Refer to Section 14 Lesson 1.

7. When a
table is Mark for Review
dropped, all (1) Points
PL/SQL
subprograms
that
reference
the table are
automatically
dropped.
True or
False?

True
False (*)

Incorrect. Refer to Section 14 Lesson 1.

8. Function
FETCH_EMP Mark for Review
references (1) Points
the
EMPLOYEES
table. The
table is
modified by:
ALTER TABLE
employees
ADD (resume
CLOB);

When will the


ORACLE
server try to
recompile
FETCH_EMP
automatically?

When the RESUME column is dropped from the EMPLOYEES table


When the command ALTER FUNCTION fetch_emp COMPILE; is executed
When FETCH_EMP is dropped and recreated
The next time a user session invokes FETCH_EMP (*)

Incorrect. Refer to Section 14 Lesson 1.

9. A single
PL/SQL Mark for Review
subprogram (1) Points
such as a
procedure
can be both
a referenced
object and a
dependent
object. True
or False?

True
(*)
False

Correct

10. Examine the following


code: Mark for Review
(1) Points
CREATE VIEW
ed_view AS
SELECT * FROM
employees NATURAL
JOIN departments;
CREATE PROCEDURE
ed_proc IS
CURSOR ed_curs IS
SELECT * FROM
ed_view;

Which of the
following statements
about dependencies
are true? (Choose
two.)

(Choose all correct


answers)

EMPLOYEES is
referenced by
ED_VIEW. (*)
ED_PROC is
referenced by
ED_VIEW.
ED_CURS is
directly
dependent on
ED_VIEW.
ED_PROC is
indirectly
dependent on
DEPARTMENTS.
(*)
ED_PROC is
directly
dependent on
EMPLOYEES.

Incorrect. Refer
to Section 14
Lesson 1.

11. Procedure B
has the Mark for Review
ZERO_DIVIDE (1) Points
pre-defined
exception
added to its
EXCEPTION
section. It is
compiled
successfully.
In Timestamp
Mode,
Procedure A,
which is
dependent on
remote
Procedure B,
will compile
and execute
successfully.
True or
False?

True
False (*)

Incorrect. Refer to Section 14 Lesson 2.

12. A change in a
remote Mark for Review
referenced (1) Points
subprogram is
automatically
recorded as
invalid if its
base object
changes and
that new
status is
relayed to the
dependent
object's status
and
automatically
marked as
invalid. True or
False?

True
False (*)

Incorrect.
Refer to
Section
14
Lesson 2.

13. If two
related Mark for Review
objects are (1) Points
in different
databases,
the
dependency
between
them is
automatically
recorded on
the
dependent
object's data
dictionary.
True or
False?

True
False (*)

Incorrect. Refer to Section 14 Lesson 2.

14. Which is not a


mode that can Mark for Review
be used to (1) Points
determine the
dependency
status of
schema
objects when
dealing with
remote
dependencies?

Time Stamp Mode


Signature Mode
All of these are valid.
Time Mode (*)

Incorrect. Refer to Section 14 Lesson 2.

15. Procedure B has a


new IN OUT Mark for Review
parameter added (1) Points
to it. It compiles
successfully.
Procedure A is
dependent on
Procedure B. In
Signature
mode,what will
happen?
Both
procedures
will execute
successfully.
Procedure B
will fail when
executed.
Both
procedures
will fail.
Procedure A
will fail when
executed. (*)

Incorrect.
Refer to
Section 14
Lesson 2.

Section 15 Quiz
(Answer all questions in this section)

1. One benefit of obfuscation is to protect intellectual property written in PL/SQL. True or


False? Mark for Review
(1) Points

True (*)
False

Correct

2. To obfuscate the procedure my_proc, what statement should be at Line A?


Mark for Review
BEGIN (1) Points
-- Line A
('CREATE OR REPLACE PROCEDURE mycleverproc
(p_param1 IN NUMBER, p_param2 OUT NUMBER)
IS BEGIN
... /* some clever but private code here */
END mycleverproc;');
END;

DBMS_DDL.CREATE_WRAP
DBMS_DDL.CREATE_WRAPPED (*)
DBMS_DDL.WRAPPED
DBMS_DML.CREATE_WRAP
DBMS_DDL.WRAP_CODE
Incorrect. Refer to Section 15 Lesson 4.

3. Which is NOT a benefit of obfuscation?


Mark for Review
(1) Points

Source code is not loaded in the data dictionary.


Source code is visible to the owner. (*)
Source code is hidden from all users.
Protection for intellectual property is provided.

Incorrect. Refer to Section 15 Lesson 4.

4. If the version and release of the Oracle database in use is 10.2, what statement will
allow syntax available in version 10.2 or later? Mark for Review
(1) Points

$IF DBMS_DB_VERSION.VER_LE_10_1 $THEN


-- some messaage
$ELSE
-- some action
$END
(*)
$IF DBMS_DB_VERSION.VER_LE_10_2 $THEN
-- some messaage
$ELSE
-- some action
$END
$IF DBMS_DB_VERSION.VER_GE_10_2 $THEN
-- some messaage
$ELSE
-- some action
$END
$IF DBMS_DB_VERSION.VER_GE_10_1 $THEN
-- some messaage
$ELSE
-- some action
$END

Correct

5. Conditional Compilation allows you to include some source code in your PL/SQL
program that may be compiled or may be ignored depending on: Mark for Review
(1) Points

Any of these could be used. (*)


The values of an initialization parameter.
The version of the Oracle software you are using.
The value of a global package constant.

Correct

6. Conditional
compilation Mark for Review
allows you (1) Points
to include
extra code
to help
with
debugging,
which can
be
removed
once errors
are
resolved.
True or
False?

True (*)
False

Correct

7. The value of DBMS_DB_VERSION.VER_LE_11 is TRUE when the version of the


Oracle database is version 11 or greater. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 15 Lesson 3.

8. To set the PLSQL_CODE_TYPE to its fastest execution speed, which command


do you use? Mark for Review
(1) Points

ALTER SESSION SET PLSQL_CODE_TYPE = INTERPRETED;


ALTER SYSTEM SET PLSQL_CODE_TYPE=2;
ALTER SESSION SET PLSQL_CODE_TYPE = NATIVE; (*)
ALTER SESSION SET PLSQL_CODE_TYPE = 2;
ALTER SYSTEM SET PLSQL_CODE_TYPE=NATIVE;

Incorrect. Refer to Section 15 Lesson 1.


9. Native compilation always runs faster; therefore SQL statements in PL/SQL will
always run faster, also. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 15 Lesson 1.

10. When setting PLSQL_OPTIMIZE_LEVEL = 2, the compiled code will remove


code and exceptions that can never be executed. True or False? Mark for Review
(1) Points

True (*)
False

Correct

11.Which are NOT


examples of benefits of Mark for
using Review
PLSQL_OPTIMIZE_LEVE
(1) Points
L. (Choose two)

(Choose all correct answers)

Backward compatible with previous versions of the Oracle


database
Separating compiled code so that separate units may be
repeated as needed (*)
Combining compiled code from one subprogram into another
subprogram
Control what PL/SQL does with useless code
Modify source code to optimize frequently-used elements at
the top (*)

Incorrect. Refer to Section 15 Lesson 1.

12. A warning in PL/SQL is the same as an error in PL/SQL, but can


only be viewed through the USER_ERRORS data dictionary view. Mark for
True or False? Review
(1) Points

True
False (*)
Incorrect. Refer to Section 15 Lesson 2.

13. Which PL/SQL warning message identifies code that can cause
unexpected behavior or wrong results when executed? Mark for
Review
(1) Points

INFORMATIONAL
SEVERE (*)
ERROR
ALL
PERFORMANCE

Incorrect. Refer to Section 15 Lesson 2.

14. Which pair of DBMS_WARNING commands would allow you to


obtain the current settings and change and restore those settings Mark for
in a PL/SQL subprogram? (Choose two) Review
(1) Points

(Choose all correct answers)

DBMS_WARNING.ADD_WARNING_SETTING_CAT
DBMS_WARNING.GET_WARNING_STRING
DBMS_WARNING.SET_WARNING_SETTING_STRING (*)
DBMS_WARNING.GET_WARNING_SETTING_STRING (*)

Incorrect. Refer to Section 15 Lesson 2.

15. An error in PL/SQL is when the compiler does not proceed


successfully and an error message is displayed. True or False? Mark for
Review
(1) Points

True (*)
False

Correct
1.The two statements below are
equivalent. True or False? Mark for
Review
DBMS_WARNING.SET_WARNING_SETT (1) Points
ING_STRING
('ENABLE:SEVERE','SESSION');

and

ALTER SESSION
SET PLSQL_WARNINGS =
'ENABLE:SEVERE';

True
False (*)

Incorrect. Refer to Section 15


Lesson 2.

2. The informational warning level for PL/SQL compiled


code identifies the code that may cause execution speed Mark for
to be slow. True or False? Review
(1) Points

True
False (*)

Incorrect. Refer to Section 15


Lesson 2.

3. Which PL/SQL warning message identifies code that can


cause unexpected behavior or wrong results when Mark for
executed? Review
(1) Points

ALL
PERFORMANCE
INFORMATIONAL
ERROR
SEVERE (*)

Incorrect. Refer to Section 15


Lesson 2.

4. Which pair of DBMS_WARNING commands would allow


you to obtain the current settings and change and Mark for
restore those settings in a PL/SQL subprogram? (Choose Review
two)
(1) Points
(Choose all correct answers)

DBMS_WARNING.SET_WARNING_SETTING_STRIN
G (*)
DBMS_WARNING.GET_WARNING_STRING
DBMS_WARNING.GET_WARNING_SETTING_STRIN
G (*)
DBMS_WARNING.ADD_WARNING_SETTING_CAT

Correct

5. When setting PLSQL_OPTIMIZE_LEVEL = 2, the


compiled code will remove code and exceptions that can Mark for
never be executed. True or False? Review
(1) Points

True (*)
False

Correct

6. Native
machine Mark for Review
code (1) Points
PL/SQL
will always
execute
faster than
bytecode
PL/SQL
because it
need not
be
interpreted
at run
time. True
or False?

True (*)
False

Correct

7. Which data dictionary view allows you to see the setting for
PLSQL_OPTIMIZE_LEVEL? Mark for Review
(1) Points
USER_PLSQL_CODE_TYPE
USER_PLSQL_OBJECTS
USER_OBJECT_SETTINGS
USER_PLSQL_OPTIMIZE
USER_PLSQL_OBJECT_SETTINGS (*)

Incorrect. Refer to Section 15 Lesson 1.

8. What is the name of the column used to identify the PLSQL_OPTIMIZE_LEVEL


in the data dictionary? Mark for Review
(1) Points

PLSQL_CODE_TYPE
PLSQL_LEVEL
USER_PLSQL_OPTIMIZE
PLSQL_OPTIMIZE_LEVEL (*)
OPTIMIZE_LEVEL

Incorrect. Refer to Section 15 Lesson 1.

9. For PL/SQL code larger than 32,767 characters, you must use the wrap utility.
True or False? Mark for Review
(1) Points

True (*)
False

Correct

10. One benefit of obfuscation is to protect intellectual property written in PL/SQL.


True or False? Mark for Review
(1) Points

True (*)
False

Correct

11. You created a


package Mark for Review
named pkg1. (1) Points
The code is
approximately
90,000
characters.
What is the
statement
that you use
to obfuscate
this package
in the
database?

DBMS_DDL.CREATE_WRAPPED (pkg1);
WRAP pkg1.sql
DBMS_DDL.CREATE_WRAPPED ('CREATE OR REPLACE PACKAGE
BODY pkg1...);
WRAP INAME=pkg1.sql (*)
DBMS_DDL.CREATE_WRAP (pkg1);

Incorrect. Refer to Section 15 Lesson 4.

12. To include selections of code for compilation based on user-defined values,


use the PLSQL_CCFLAGS parameters. True or False? Mark for Review
(1) Points

True (*)
False

Correct

13. The value of DBMS_DB_VERSION.VER_LE_11 is TRUE when the version of


the Oracle database is version 11 or greater. True or False? Mark for Review
(1) Points

True
False (*)

Incorrect. Refer to Section 15 Lesson 3.

14. Identify the selection directives used in conditional compilation.


Mark for Review
(1) Points

$$IF
$$THEN
$$ELSE
$$ELSIF
$$END
$$IF
$$THEN
$$ELSE
$$END
$$DEBUG
$IF
$THEN
$ELSE
$ELSIF
$END
(*)
$IF
$THEN
$ELSE $ELSIF
$ENDIF
$IF
$THEN
$ELSE
$END
$CCFLAG

Incorrect. Refer to Section 15 Lesson 3.

15. Conditional compilation allows you to include extra code to help with
debugging, which can be removed once errors are resolved. True or False? Mark for Review
(1) Points

True (*)
False

Correct

Вам также может понравиться