Dokumen - Tips Oracle PLSQL Semester 1
Dokumen - Tips Oracle PLSQL Semester 1
Correct
Correct
Correct
4. Which of the following statements about SQL is true? Mark for Review
(1) Points
SQL is an Oracle proprietary, nonprocedural, 4GL programming language.
SQL is an Oracle proprietary, procedural, 3GL programming language.
SQL is an ANSI-compliant, nonprocedural, 4GL programming language. (*)
SQL is an ANSI-compliant, procedural, 4GL programming language.
Correct
5. In which three ways does PL/SQL extend the SQL programming language? Mar
k for Review
(1) Points
(Choose all correct answers)
By adding procedural constructs. (*)
By adding compound constructs.
By adding iterative control. (*)
By adding conditional control. (*)
Correct
Correct
2. You can create a Web site application written entirely in PL/SQL. True or
False? Mark for Review
(1) Points
True (*)
False
3. 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 requires an Oracle database or tool. (*)
It does not support object-oriented programming.
It is the most efficient language to use with an Oracle database. (*)
It is the most complex programming language to learn.
It is not portable to other operating systems.
4. Procedural constructs give you better control of your SQL statements and t
heir execution. True or False? Mark for Review
(1) Points
True (*)
False
Correct
6. When multiple SQL statements are combined into PL/SQL blocks, performance
improves. True or False? Mark for Review
(1) Points
True (*)
False
Correct
Quiz: Creating PL/SQL Blocks
1. What are the characteristics of an anonymous block? (Choose two.) Mark for
Review
(1) Points
(Choose all correct answers)
Unnamed (*)
Stored in the database
Compiled each time the application is executed (*)
Correct
Correct
Correct
4. Which statements are mandatory in a PL/SQL block? (Choose two.) Mark for
Review
(1) Points
(Choose all correct answers)
DECLARE
BEGIN (*)
EXCEPTION
END; (*)
Correct
5. How can you display results to check that a PL/SQL block is working correc
tly? Mark for Review
(1) Points
You don't need to do anything, the results will display automatically.
Use an Exception section
Use DBMS_OUTPUT.PUT_LINE (*)
Write a C or Java program to display the results
Correct
Correct
Correct
Correct
Correct
10. This PL/SQL anonymous block will execute successfully. True or False?
DECLARE
v_date DATE := SYSDATE;
DBMS_OUTPUT.PUT_LINE(v_date);
END;
Mark for Review
(1) Points
True
False (*)
Correct
11. Which lines of code will correctly display the message "Hello World" ? (C
hoose two.) Mark for Review
(1) Points
(Choose all correct answers)
DBMS_OUTPUT('Hello World');
DBMS_OUTPUT.PUT_LINE('Hello World'); (*)
DBMS_OUTPUT.PUT_LINE('Hello' || 'World');
DBMS_OUTPUT.PUT_LINE('Hello' || ' ' || 'World'); (*)
Correct
Section 2
(Answer all questions in this section)
Quiz: Using Variables PL/SQL
1. A function called FORMAT_TODAYS_DATE accepts no parameters and returns today
's date in the format: Month DD, YYYY
The following anonymous block invokes the function:
DECLARE v_today DATE; BEGIN -- invoke the function here
Which of the following statements correctly assigns the date variable v_today to
the value returned by the format_todays_date function?
Mark for Review
(1) Points
format_todays_date := v_today('Month DD, YYYY');
v_today := format_todays_date ('Month DD, YYYY');
v_today := format_todays_date(v_today);
v_today := TO_DATE(format_todays_date, 'Month DD, YYYY'); (*)
Correct
Correct
6. Which of the following are required when declaring a variable? (Choose two
.) Mark for Review
(1) Points
(Choose all correct answers)
Correct
8. After they are declared, variables can be used only once in an application
. True or False? Mark for Review
(1) Points
True
False (*)
2. What characters must enclose non-numeric literal values? Mark for Review
(1) Points
Double quotes: " "
Parentheses: ()
3. Which of the following are lexical units? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)
Data types
PL/SQL blocks
Identifiers (*)
Literals (*)
Correct
Correct
Correct
1. A datatype may specify a valid range of values. True or False? Mark for
Review
(1) Points
True (*)
False
2. Which of the folowing are scalar data types? (Choose three.) Mark for Re
view
(1) Points
(Choose all correct answers)
Array
Character (*)
Table
Date (*)
Boolean (*)
3. A datatype specifies and restricts the possible data values that can be as
signed to a variable. True or False? Mark for Review
(1) Points
True (*)
False
CLOB
VARCHAR2
RECORD (*)
DATE
5. What are the data types of the variables in the following declaration?
DECLARE
fname VARCHAR2(20);
fname VARCHAR2(15) DEFAULT 'fernandez';
BEGIN
...
Mark for Review
(1) Points
Scalar (*)
Composite
LOB
Correct
Single (*)
Correct
7. Which of the following are PL/SQL data types? (Choose three.) Mark for R
eview
(1) Points
(Choose all correct answers)
Large Objects (LOB) (*)
Lexical
Scalar (*)
Delimiter
Composite (*)
1. If you use the %TYPE attribute, you can avoid hard-coding the column name. T
rue or False? Mark for Review
(1) Points
True
False (*)
Correct
2. Which of the following is NOT a character data type? Mark for Review
(1) Points
VARCHAR2
BOOLEAN (*)
CHAR
LONG
Correct
3. When declared using %TYPE, a variable will inherit ____ from the column on
which it is based. Mark for Review
(1) Points
Correct
4. Code is easier to read if you declare one identifier per line. True or Fal
se? Mark for Review
(1) Points
True (*)
False
Correct
6. Which of the following variable declarations does NOT use a number data ty
pe? Mark for Review
(1) Points
v_count PLS_INTEGER := 0;
v_median_age NUMBER(6,2);
v_students LONG; (*)
v_count BINARY_INTEGER;
1. The DECODE and MAX functions can be used in PL/SQL statements. True or Fal
se? Mark for Review
(1) Points
True
False (*)
Correct
v_family_name = SMITH;
V_FAMILY_NAME = SMITH;
v_family_name := SMITH;
v_family_name := 'SMITH'; (*)
4. Which of the following are valid PL/SQL operators? (Choose three.) Mark
for Review
(1) Points
(Choose all correct answers)
Concatenation (*)
Exception
Exponential (*)
Arithmetic (*)
5. The LENGTH and ROUND functions can be used in PL/SQL statements. True or F
alse? Mark for Review
(1) Points
True (*)
False
Correct
7. The TO_CHAR function is used for explicit data type conversions. True or F
alse? Mark for Review
(1) Points
True (*)
False
10. Which of the following statements about implicit conversions is NOT true?
Mark for Review
(1) Points
Code containing implicit conversions typically runs faster than code contain
ing explicit conversions. (*)
Code containing implicit conversions may not work in the future if Oracle ch
anges the conversion rules.
Code containing implicit conversions is harder to read and understand.
11. PL/SQL statements must be written on a single line. Mark for Review
(1) Points
True
False (*)
Correct
13. When PL/SQL converts data automatically from one data type to another, it
is called _______ conversion. Mark for Review
(1) Points
Explicit
Implicit (*)
TO_CHAR
Correct
14. Using implicit conversions is good programming practice. Mark for Revie
w
(1) Points
True
False (*)
15. Which of the following data type conversions can be done implicitly? (Cho
ose two.) Mark for Review
(1) Points
(Choose all correct answers)
DATE to NUMBER
NUMBER to VARCHAR2 (*)
NUMBER to PLS_INTEGER (*)
2. Examine the following nested blocks. Line B causes an exception. What will
be displayed when this code is executed?
DECLARE
var_1 NUMBER;
BEGIN
var_1 := 4;
DECLARE
var_2 NUMBER;
BEGIN
var_2 := 'Unhappy'; -- Line B
var_1 := 8;
END;
var_1 := 12;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(var_1);
END;
Mark for Review
(1) Points
Unhappy
12
8
4 (*)
4. For the anonymous block below, what is the correct reference to the father
's date of birth in the inner block?
<<outer>>
DECLARE
v_father_name VARCHAR2(20):='Patrick';
v_date_of_birth DATE:='20-Apr-1972';
BEGIN
DECLARE
v_child_name VARCHAR2(20):='Mike';
v_date_of_birth DATE:='12-Dec-2002';
...
Mark for Review
(1) Points
v_date_of_birth.outer
<<outer>>v_date_of_birth
<<outer.v_date_of_birth>>
outer.v_date_of_birth (*)
5. Examine the following code. Line A causes an exception. What will be displ
ayed when the block is executed?
DECLARE
x NUMBER := 10;
y NUMBER;
BEGIN
x := 15;
y := 'Happy'; -- Line A
x := 20;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(x);
END;
Mark for Review
(1) Points
10
20
15 (*)
Nothing is displayed
It cannot be done because the outer block's v_myvar is out of scope at Line
A.
Label the outer block and (at Line A) dot-prefix v_myvar with the block labe
l.
(*)
It cannot be done because the outer block's v_myvar is in scope but not visi
ble at Line A.
1. Which of the following makes PL/SQL code easier to read and maintain? Mark
for Review
(1) Points
Correct
Correct
Section 3
(Answer all questions in this section)
Quiz: Review of SQL DML
1. Look at this SQL statement:
MERGE INTO old_trans ot
USING new_trans nt
ON (ot.trans_id = nt.trans_id) .... ;
OLD_TRANS is the source table and NEW_TRANS is the target table. True or false?
Mark for Review
(1) Points
True
False (*)
Correct
3. When 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 (*)
Correct
4. To modify an existing row in a table, you can use the ________ statement.
Mark for Review
(1) Points
MODIFY
INSERT
ALTER
UPDATE (*)
Correct
6. Is it possible to insert more than one row at a time using an INSERT state
ment with a VALUES clause? Mark for Review
(1) Points
No, you can only create one row at a time when using the VALUES clause. (*)
Yes, you can list as many rows as you want, just remember to separate the ro
ws with commas.
No, there is no such thing as INSERT ... VALUES.
8. You want to modify existing rows in a table. Which of the following are NO
T needed in your SQL statement? (Choose two). Mark for Review
(1) Points
(Choose all correct answers)
A MODIFY clause. (*)
An UPDATE clause.
The name of the table.
Correct
3. Which of the following is NOT a valid guideline for retrieving data in PL/
SQL? Mark for Review
(1) Points
Terminate the SQL statement with a semicolon (;)
Do NOT use a WHERE clause in SELECT statements. (*)
Where possible, declare variables using the %TYPE attribute.
Specify the same number of variables in the INTO clause as database columns
in the SELECT clause.
Correct
4. Which SQL statements can be used directly in a PL/SQL block? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)
GRANT EXECUTE ON ...
SELECT * INTO ... (*)
REVOKE SELECT ON ...
UPDATE employees SET... (*)
ALTER TABLE employees ...
5. Which one of these SQL statements can be directly included in a PL/SQL exe
cutable block? Mark for Review
(1) Points
IF... THEN...;
INSERT INTO...; (*)
SELECT * FROM DUAL;
SHOW USER;
6. When used in a PL/SQL block, which SQL statement must return exactly one r
ow? Mark for Review
(1) Points
INSERT
UPDATE
SELECT (*)
MERGE
DELETE
7. Does PL/SQL allow you to have a variable with the same name as a database
column? Mark for Review
(1) Points
No
Yes (*)
Incorrect. Refer to Section 3 Lesson 2.
The block will fail because V_LAST was declared before V_FIRST.
The block will execute successfully, and the V_SALARY variable will be set t
o NULL.
Correct
3. You can use implicit cursor attributes such as SQL%ROWCOUNT directly insid
e a DML statement. For example:
INSERT INTO log_table
VALUES (SYSDATE, USER,
SQL%ROWCOUNT);
True or False?
Mark for Review
(1) Points
True
False (*)
Correct
4. Employee_id 999 does not exist. What will happen when the following code i
s executed?
DECLARE
employee_id employees.employee_id%TYPE := 999;
BEGIN
UPDATE employees SET salary = salary * 1.1
WHERE employee_id = employee_id;
END;
Mark for Review
(1) Points
No rows are updated but the block completes successfully.
Every employee row is updated. (*)
An exception is raised because you cannot give a variable the same name as a
table column.
An exception is raised because the UPDATE statement did not modify any rows.
Correct
6. Which of the following SQL DML commands can be used inside a PL/SQL block?
Mark for Review
(1) Points
INSERT and UPDATE only.
7. There are three employees in department 90. What will be displayed when th
e following code is executed? DECLARE v_open CHAR(3) := 'NO'; BEGIN UPDATE emplo
yees 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; Ma
rk for Review
(1) Points
NO 3
YES 1
YES 3 (*)
Nothing will be displayed. The block will fail because you cannot use implic
it cursor attributes directly in a call to DBMS_OUTPUT.PUT_LINE.
1. How many INSERTs can you have in one transaction? Mark for Review
(1) Points
One
As many as you want until you do a COMMIT or ROLLBACK. (*)
As many as you can execute before the database does an AUTOSAVE.
As many as you want until a different DML statement (UPDATE, DELETE or MERGE
) is executed.
Correct
2. In a PL/SQL block, where can you code a COMMIT statement? Mark for Revie
w
(1) Points
In any section of the block: Declaration, Executable, or Exception.
Only the Executable section.
In the Executable and/or the Exception sections. (*)
Nowhere; the COMMIT statement must be outside the block.
Two; both the INSERTs are one transaction and both the UPDATEs are a second
transaction.
It depends on how many rows are updated - there will be a separate transacti
on for each row.
One (*)
Correct
Section 4
(Answer all questions in this section)
2. Which of the following statements are true about any of the PL/SQL conditi
onal control structures such as IF ... , CASE ... and loops? Mark for Review
(1) Points
They allow the programmer to use logical tests to determine which statements
are executed and which are not.
They allow a set of statements to be executed repeatedly (i.e. more than onc
e).
They determine a course of action based on conditions.
All of the above. (*)
3. A basic loop is a type of control structure used to change the logical flo
w of statements in a PL/SQL block. True or False? Mark for Review
(1) Points
True (*)
False
Correct
child
teenager
adult (*)
adultteenagerchild
Correct
Correct
IF condition THEN
statement1;
statement2;
END IF;
(*)
IF condition THEN
statement1;
statement2;
ENDIF;
IF condition THEN
statement1;
AND statement2;
END IF;
Correct
Correct
Correct
Correct
Correct
Correct
Correct
3. What are the three kinds of loops in PL/SQL? Mark for Review
(1) Points
ascending, descending, unordered
infinite, finite, recursive
IF, CASE, LOOP
FOR, WHILE, basic (*)
Correct
5. For which one of these tasks should you use a PL/SQL loop? Mark for Revi
ew
(1) Points
Updating the salary of one employee.
Executing the same set of statements repeatedly until a condition becomes tr
ue. (*)
Deciding whether a value is within a range of numbers.
Making a decision based on whether a condition is true or not.
Correct
Twice.
Never (the SELECT will not execute at all) (*)
An infinite number of times because the EXIT condition will never be true
Correct
7. You want to calculate and display the multiplication table for "sevens": 7
x1=7, 7x2=14, 7x3=21 and so on. Which kind of PL/SQL construct is best for this?
Mark for Review
(1) Points
A loop (*)
A CASE statement
IF ... END IF;
A Boolean variable.
8. How many EXIT statements can be coded inside a basic loop? Mark for Revi
ew
(1) Points
None.
One only.
Two.
As many as you need, there is no limit. (*)
Incorrect. Refer to Section 4 Lesson 3.
Section 5
Quiz: Iterative Control: While and For Loops
1. You want a loop that counts backwards from 10 through 1. How do you code tha
t? Mark for Review
(1) Points
FOR i IN 10 .. 1 LOOP
FOR i IN 1 .. 10 BY -1 LOOP
FOR i IN REVERSE 1 .. 10 LOOP (*)
FOR i IN REVERSE 10 .. 1 LOOP
3. You should use a WHILE loop when the number of iterations of the loop is k
nown in advance. True or False? Mark for Review
(1) Points
True
False (*)
8. Which statement best describes when a FOR loop should be used? Mark for
Review
(1) Points
When an EXIT WHEN statement must be coded.
When an implicitly declared counter must increase by 1 in each iteration of
the loop. (*)
When we want to exit from the loop when a Boolean variable becomes FALSE.
When the statements inside the loop must execute at least once.
Correct
3. When the following code is executed, how many lines of output will be disp
layed?
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;
Mark for Review
(1) Points
80
45 (*)
14
41
4. Which one of these statements about using nested loops is true? Mark for
Review
(1) Points
All the loops must be labelled
The outer loop must be labelled, but the inner loop need not be labelled
The outer loop must be labelled if you want to exit the outer loop from with
in the inner loop (*)
Both loops can have the same label
5. What statement allows you to exit the outer loop at Point A in the followi
ng block?
DECLARE
v_outer_done CHAR(3) := 'NO';
v_inner_done CHAR(3) := 'NO';
BEGIN
LOOP -- outer loop
...
LOOP -- inner loop
...
... -- Point A
EXIT WHEN v_inner_done = 'YES';
...
END LOOP;
...
EXIT WHEN v_outer_done = 'YES';
...
END LOOP;
END;
Mark for Review
(1) Points
EXIT AT v_outer_done = 'YES';
EXIT WHEN v_outer_done = 'YES'; (*)
WHEN v_outer_done = YES EXIT;
EXIT <<outer loop>>;
Correct
Correct
1. You have declared a cursor EMP_CURSOR to select many rows from the EMPLOYEES
table. The following five statements will be in the executable section:
A FETCH emp_cursor INTO v_empno,v_last_name;
B OPEN emp_cursor;
C END LOOP;
D CLOSE emp_cursor;
E LOOP
In which order should you code these statements?
Mark for Review
(1) Points
B, E, A, C, D (*)
E, B, A, C, D
B, E, A, D, C
B, A, E, D, C
Correct
Correct
3. When must you declare and use an explicit cursor? Mark for Review
(1) Points
You need to UPDATE more than one row in a table.
Correct
Correct
6. You cannot OPEN or CLOSE an implicit cursor. Why not? Mark for Review
(1) Points
Correct
7. Which one of the following statements is NOT true? Mark for Review
(1) Points
You can use ORDER BY when declaring an explicit cursor.
You can not use an INTO clause when declaring an explicit cursor.
An explicit cursor can select from only one table. No joins are allowed. (*)
8. One (and only one) employee has LAST_NAME = 'Grant'. You need to code:
SELECT ... FROM employees WHERE last_name = 'Grant';
Which type of cursor should you use, and why?
Mark for Review
(1) Points
An implicit cursor, because there is only one 'Grant'.
An implicit cursor, because SELECT is a SQL statement and implicit cursors a
re always called "SQL".
An explicit cursor, because there could be more than one 'Grant' in the futu
re. (*)
An explicit cursor, because you can use an implicit cursor only for DML stat
ements.
Correct
Correct
11. You must make sure you have the same number of variables in your INTO sta
tement as you have in your SELECT list. True or False? Mark for Review
(1) Points
True (*)
False
Correct
12. Which statement correctly places the employee id and last name into the s
tated variables?
DECLARE
CURSOR emp_cursor IS
SELECT employee_id, last_name FROM employees
WHERE department_id = 30;
v_empno employees.employee_id%TYPE;
v_lname employees.last_name%TYPE;
BEGIN
OPEN emp_cursor;
-- Point A
...
Mark for Review
(1) Points
GET emp_cursor INTO v_empno, v_lname;
FETCH emp_cursor INTO v_empno, v_lname; (*)
GET emp_cursor.employee_id, emp_cursor.last_name INTO v_empno, v_lname;
FETCH emp_cursor.employee_id, emp_cursor.last_name INTO v_empno, v_lname;
Correct
13. There are 8 countries in REGION_ID 13 (Central America). What will happen
when the following code is executed?
DECLARE
CURSOR country_curs IS SELECT country_name FROM wf_countries
WHERE region_id = 13;
v_country_name wf_countries.country_name%TYPE;
BEGIN
OPEN country_curs;
WHILE country_curs%FOUND
LOOP
FETCH country_curs INTO v_country_name;
DBMS_OUTPUT.PUT_LINE(v_country_name);
END LOOP;
CLOSE country_curs;
END;
Mark for Review
(1) Points
Eight rows will be fetched and displayed successfully.
The last seven rows will be fetched and displayed.
14. Which of the following best describes the difference between implicit and
explicit cursors? Mark for Review
(1) Points
Implicit cursors are used for SELECT statements, while explicit cursors are
used for DML statements.
Implicit cursor are named by the PL/SQL programmer, while explicit cursors a
re always named SQL.
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 me
mory.
Correct
Correct
Correct
7. How must you reference one field which is part of a PL/SQL record? Mark
for Review
(1) Points
field_name.record_name
record_name.field_name (*)
record_name(field_name)
field_name OF record_name
It cannot be done.
2. A cursor FOR loop using a subquery can extensively shorten code length whe
n compared to an explicit cursor declaration. True or False? Mark for Review
(1) Points
True (*)
False
Correct
3. Which one of the following is a valid cursor FOR loop with a subquery? M
ark for Review
(1) Points
FOR emp_rec IN (SELECT last_name || first_name FROM employees) LOOP ...
FOR emp_rec IN (SELECT UPPER(last_name) FROM employees) LOOP ...
FOR emp_rec IN SELECT last_name, salary*12 "ANNSAL" FROM employees LOOP ...
FOR emp_rec IN (SELECT last_name, salary*12 "ANNSAL" FROM employees) LOOP ..
. (*)
4. What is the DISadvantage of using a cursor FOR loop with a subquery? Mar
k for Review
(1) Points
You cannot reference cursor attributes such as %NOTFOUND. (*)
The execution speed is slower.
You cannot declare the cursor in the declaration section.
You cannot use the cursor to join two or more tables.
There are no disadvantages.
Correct
Correct
3. You want to use explicit cursors to fetch and display all the countries in
a specific region. There are 19 rows in the WF_WORLD_REGIONS table. You want to
use a different region each time the cursor is opened. How many cursors should
you declare? Mark for Review
(1) Points
19 cursors, all in the same PL/SQL block.
19 cursors in 19 PL/SQL blocks (one in each block).
20 cursors, in case an extra row is inserted into WF_WORLD_REGIONS later.
One cursor with a parameter in the WHERE clause. (*)
None of the above.
4. Using parameters with a cursor, you can open and close the cursor several
times in a block, returning a different active set each time. True or False? M
ark for Review
(1) Points
True (*)
False
Correct
100 / 2
All of the above. (*)
Correct
2. When can we use the WHERE CURRENT OF clause? Mark for Review
(1) Points
Only with an UPDATE, not with a DELETE.
Only with a DELETE, not with an UPDATE.
When the cursor is declared as SELECT ... FOR UPDATE ...; (*)
When the cursor is based on a single table (not on a join).
When the cursor has not been OPENed.
Correct
4. If the rows you attempt to reserve using FOR UPDATE have already been lock
ed by another session and you use the NOWAIT option, what is the outcome? Mark
for Review
(1) Points
The block executes successfully with no errors.
The server will wait until the locks have been released by the other user.
6. You want to fetch rows from the EMPLOYEES table. You want to lock the fetc
hed rows, to prevent other users from updating them. You declare the following c
ursor:
CURSOR emp_curs IS
SELECT employee_id, last_name, salary
FROM employees
-- Line A -- ;
What should you code at Line A?
What should you code at Line A?
Mark for Review
(1) Points
FOR LOCK
FOR UPDATE OF employees
FOR UPDATE (*)
FOR UPDATE (employees)
Correct
7. 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 fo
r Review
(1) Points
When an UPDATE ... WHERE CURRENT OF cursor_name; is executed.
When you CLOSE the cursor.
When your block finishes executing.
When you explicitly COMMIT or ROLLBACK your transaction. (*)
When another user tries to SELECT the rows.
Correct
1. Assume that table BIGDEPTS contains 100 rows, and table BIGEMPS contains 100
0 rows, with 10 employees in each department. Consider the following code:
DECLARE
CURSOR bigdept_cur IS
SELECT * FROM bigdepts;
CURSOR bigemp_cur IS
SELECT * FROM bigemps;
BEGIN
FOR dept_rec IN bigdept_cur LOOP
DBMS_OUTPUT.PUT_LINE (dept_rec.department_name);
FOR emp_rec IN bigemp_cur LOOP
IF emp_rec.department_id=dept_rec.department_id
THEN DBMS_OUTPUT.PUT_LINE (emp_rec.last_name);
END IF;
END LOOP;
END LOOP;
END;
Why is this code inefficient?
Mark for Review
(1) Points
It locks both tables unnecessarily.
It is using two cursors when one cursor is enough.
It is doing a Cartesian Product, joining every employee with every departmen
t and displaying 1100 lines of output.
It reads 1000 employee rows every time BIGEMP_CUR is OPENed, and then ignore
s 990 of them. (*)
It is using cursor FOR loops, which are less efficient than OPENing and CLOS
Eing the cursors explicitly.
Correct
2. Which of the following is NOT allowed when using multiple cursors with par
ameters? Mark for Review
(1) Points
You cannot use cursor FOR loops.
You cannot declare the cursors FOR UPDATE.
You cannot declare a cursor based on a join.
You cannot OPEN more than one cursor at the same time.
None of the above, they are all allowed. (*)
Correct
3. Assume your schema contains 25 tables. How many explicit cursors can you d
eclare and use within a single PL/SQL block? Mark for Review
(1) Points
Only one.
As many as you need - there is no limit. (*)
A maximum of three.
As many as you need, but only one of them can be open at any time.
A maximum of 25 (one for each table in your schema).
5. You want to produce a report which displays each department and (immediate
ly after each department) a list of employees who work in that department. You d
eclare a DEPARTMENTS cursor as:
CURSOR dept_curs IS
SELECT * FROM departments
ORDER BY department_id;
How could you declare the EMPLOYEES cursor? (Choose two).
Mark for Review
(1) Points
(Choose all correct answers)
CURSOR emp_curs IS
SELECT * FROM employees;
CURSOR emp_curs IS
SELECT * FROM employees
ORDER BY department_id;
CURSOR emp_curs
(p_dept_id departments.department_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id;
(*)
CURSOR emp_curs IS
SELECT * FROM employees
WHERE department_id = departments.department_id;
Incorrect. Refer to Section 5 Lesson 6.
Section 6
Quiz: User-Defined Records
1. Which of the following will successfully create a record type containing two
fields, and a record variable of that type? Mark for Review
(1) Points
TYPE person_type IS RECORD
(l_name VARCHAR2(20),
gender CHAR(1));
person_rec TYPE person_type;
TYPE person_type IS RECORD
(l_name VARCHAR2(20),
gender CHAR(1));
person_rec person_type;
(*)
3. The following code declares a PL/SQL record with the same structure as a r
ow of the departments table. True or False?
DECLARE
v_dept_rec departments%ROWTYPE;
...
Mark for Review
(1) Points
True (*)
False
Correct
Quiz: Indexing Tables of Records
1. 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
2. Which of these PL/SQL data structures could store a complete copy of the e
mployees 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;
5. Which of these PL/SQL data structures can NOT store a collection? Mark f
or Review
(1) Points
A PL/SQL record (*)
An INDEX BY table of records
An INDEX BY table indexed by PLS_INTEGER
An INDEX BY table indexed by BINARY_INTEGER
DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;
(*)
DECLARE
TYPE t_depttab IS INDEX BY TABLE OF departments%ROWTYPE
INDEX BY BINARY_INTEGER;
DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE
INDEX BY NUMBER;
Section 7
Quiz: Handling Exceptions
1. Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL
block? Mark for Review
(1) Points
An attempt is made to divide by zero
A SELECT statement returns no rows
Any other kind of exception that can occur within the block
All of the above (*)
None of the above
2. Examine the following code. Why does this exception handler not follow goo
d practice guidelines? (Choose two.)
DECLARE
v_dept_name departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_dept_name FROM departments
WHERE department_id = 75;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('A select returned more than one row');
END;
Mark for Review
(1) Points
(Choose all correct answers)
You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.
department_id 75 does not exist in the departments table.
The exception handler should test for the named exception NO_DATA_FOUND. (*
)
The exception handler should COMMIT the transaction.
3. Which of the following are NOT good practice guidelines for exception hand
ling? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)
Test your code with different combinations of data to see what potential er
rors can happen.
Use an exception handler whenever there is any possibility of an error occu
rring.
Include a WHEN OTHERS handler as the first handler in the exception section
. (*)
Allow exceptions to propagate back to the calling environment. (*)
Handle specific named exceptions where possible, instead of relying on WHEN
OTHERS.
5. Which of the following best describes a PL/SQL exception? Mark for Revie
w
(1) Points
A user enters an invalid password while trying to log on to the database.
An error occurs during the execution of the block, which disrupts the normal
operation of the program. (*)
A compile-time error occurs because the PL/SQL code references a non-existen
t table.
The programmer forgets to declare a cursor while writing the PL/SQL code.
Correct
EXCEPTION
WHEN TOO_MANY_ROWS THEN statement_1;
END;
(*)
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
WHEN OTHERS THEN statement_3;
END;
EXCEPTION
WHEN OTHERS THEN statement_1;
END;
(*)
EXCEPTION
WHEN OTHERS THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
END;
Correct
7. Which of the following is NOT a predefined Oracle Server error? Mark for
Review
(1) Points
NO_DATA_FOUND
TOO_MANY_ROWS
e_sal_too_high EXCEPTION; (*)
ZERO_DIVIDE
DUP_VAL_ON_INDEX
Correct
8. There are no employees whose salary is less than 2000. Which exception han
dlers would successfully trap the exception which will be raised when the follow
ing code is executed? (Choose two.)
DECLARE
v_mynum NUMBER := 10;
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count FROM employees
WHERE salary < 2000;
v_mynum := v_mynum / v_count;
EXCEPTION ...
END;
Mark for Review
(1) Points
(Choose all correct answers)
NO_DATA_FOUND
ZERO_DIVIDE (*)
SQL%ROWCOUNT = 0
OTHERS (*)
OTHER
Correct
10. Which kind of error can NOT be handled by PL/SQL? Mark for Review
(1) Points
Syntax errors (*)
Predefined Oracle Server errors
Non-predefined Oracle Server errors
User-defined errors
11. Examine the following code. The UPDATE statement will raise an ORA-02291
exception.
BEGIN
UPDATE employees SET department_id = 45;
EXCEPTION
WHEN OTHERS THEN
INSERT INTO error_log_table VALUES (SQLCODE);
END;
What will happen when this code is executed?
Mark for Review
(1) Points
The code will execute and insert error number 02291 into error_log_table.
The code will fail because SQLCODE has not been declared.
The code will fail because we access error message numbers by using SQLERRNU
M, not SQLCODE.
The code will fail because we cannot use functions like SQLCODE directly in
a SQL statement. (*)
Incorrect. Refer to Section 7 Lesson 2.
12. How would you trap Oracle Server exception ORA-01403: no data found? Ma
rk for Review
(1) Points
WHEN NO DATA FOUND THEN ...
WHEN ORA-01403 THEN ...
WHEN NO_DATA_FOUND THEN ... (*)
WHEN SQL%ROWCOUNT=0 THEN ...
By PRAGMA EXCEPTION_INIT
By DECLARE e_my_excep EXCEPTION;
By RAISE exception_name; (*)
None of the above. They are raised automatically by the Oracle server.
Correct
Message 1
Message 3
Message 4
Message 1
Message 2
Message 3
Message 4
The code will not execute because it contains at least one syntax error.
The code will execute but will return an unhandled exception to the calling
environment.
(*)
Correct
6. You want to display your own error message to the user. What is the correc
t syntax to do this? Mark for Review
(1) Points
RAISE_APPLICATION_ERROR(20001, 'My own message');
RAISE_APPLICATION_ERROR('My own message', -20001);
RAISE application_error;
RAISE_APPLICATION_ERROR (-20001, 'My own message'); (*)
Correct
5. There are three employees in department 90. What will be displayed when th
is code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('Message 1');
BEGIN
SELECT last_name INTO v_last_name
FROM employees WHERE department_id = 90;
DBMS_OUTPUT.PUT_LINE('Message 2');
END;
DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Message 4');
END;
Mark for Review
(1) Points
Message 1
Message 3
Message 4
Message 1
Message 4
(*)
Message 1
Correct
Section 8
3. Which of the following are benefits of using PL/SQL subprograms rather tha
n anonymous blocks? (Choose three.) Mark for Review
(1) Points
(Choose all correct answers)
Better data security (*)
Code reuse (*)
Stored externally
Easier code maintenance (*)
Do not need to define exceptions
5. The following are the steps involved in creating, and later modifying and
re-creating, a PL/SQL procedure in Application Express. Which step is missing?
Type the procedure code in the SQL Commands window
Click on the "Save" button and save the procedure code
Retrieve the saved code from "Saved SQL" in SQL Commands
Modify the code in the SQL Commands window
Execute the code to re-create the procedure
Mark for Review
(1) Points
Enter parameters and data type
Exe ute the procedure from USRE_SOURCE data dictionary view
Execute the code to create the procedure (*)
Invoke the procedure from an anonymous block
Incorrect. Refer to Section 8 Lesson 1.
Correct
Correct
9. PL/SQL subprograms, unlike anonymous blocks, are compiled each time they a
re executed. True or False? Mark for Review
(1) Points
True
False (*)
Correct
11. A nested subprogram can be called from the main procedure or from the cal
ling environment. True or False? Mark for Review
(1) Points
True
False (*)
Correct
12. A stored PL/SQL procedure can be invoked from which of the following?
A PL/SQL anonymous block
A calling application
A SELECT statement
Another PL/SQL procedure
Mark for Review
(1) Points
A only
A and B
A and C
A, B and D (*)
B and C
Correct
1. What is the purpose of using parameters with stored procedures? Mark for R
eview
(1) Points
They prevent the procedure from modifying data in the database.
They allow values to be passed between the calling environment and the proce
dure. (*)
They count the number of exceptions raised by the procedure.
They speed up the execution of the procedure.
4. What is the correct syntax to create procedure MYPROC that accepts two num
ber parameters X and Y? Mark for Review
(1) Points
myproc(p_left, p_right);
myproc(v_left, v_right);
myproc(v_left, 30);
All of the above. (*)
3. Which kind of parameters cannot have a DEFAULT value? Mark for Review
(1) Points
OUT (*)
IN
CONSTANT
R(ead)
W(rite)
Correct
Correct
8. When creating a procedure, where in the code must the parameters be listed
? Mark for Review
(1) Points
After the procedure name. (*)
After the keyword IS or AS.
Before the procedure name.
After the keyword PROCEDURE.
9. If you don't specify a mode for a parameter, what is the default mode? M
ark for Review
(1) Points
OUT
IN (*)
COPY
DEFAULT
R(ead)
11. What will happen when the following procedure is called as format_phone (
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;
Mark for Review
(1) Points
The phone number 800.555.1234 is printed to the screen.
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 procedure does not execute because the input variable is not properly de
clared.
Section 9
Correct
3. A function may execute more than one RETURN statement found in the body of
that function. True or False? Mark for Review
(1) Points
True
False (*)
v_name := get_country_name(100);
DBMS_OUTPUT.PUT_LINE(get_country_name(100));
SELECT get_country_name(100) FROM dual;
BEGIN get_country_name(100, v_name); END; (*)
6. When using Invoker's rights, the invoker needs privileges on the database
objects referenced within the subprogram, as well as GRANT privilege on the proc
edure. True or False? Mark for Review
(1) Points
True
False (*)
Correct
The subprogram will fail because the RETURN is declared with %TYPE.
The program will compile successfully.
9. What is wrong with the following code? CREATE FUNCTION annual_comp (sal em
ployees.salary%TYPE, comm_pct IN employees.commission%TYPE) RETURN NUMBER(5,2) I
S BEGIN RETURN (sal*12) + NVL(comm_pct,0)*12*sal; END annual_comp; Mark for Re
view
(1) Points
The sal parameter should specify the IN keyword.
The RETURN NUMBER has a scale and precision. (*)
There should be parentheses (brackets) around NVL(comm_pct,0)*12*sal
The END; statement should not include the function name.
10. Procedure p1 has a single OUT parameter of type DATE. Function f1 returns
a DATE. What is the difference between p1 and f1? Mark for Review
(1) Points
p1 can be invoked from an anonymous block but f1 cannot
f1 can be used within a SQL statement but p1 cannot (*)
p1 can have as many IN parameters as needed but f1 cannot have more than two
IN parameters
There is no difference because they both return a single value of the same d
atatype
Correct
13. Function GET_JOB accepts an employee id as input and returns that employe
e's job id. Which of the following calls to the function will NOT work? Mark f
or Review
(1) Points
DBMS_OUTPUT.PUT_LINE(get_job(100));
IF get_job(100) = 'IT_PROG' THEN ...
get_job(100,v_job_id); (*)
v_job_id := get_job(100);
14. A PL/SQL function can have IN OUT parameters. True or False? Mark for R
eview
(1) Points
True
False (*)
15. Function MYFUNC1 has been created, but has failed to compile because it c
ontains syntax errors. We now try to create procedure MYPROC1 which invokes this
function. Which of the following statements is true? Mark for Review
(1) Points
MYPROC1 will compile correctly, but will fail when it is executed.
MYPROC1 will compile and execute succesfully.
MYPROC1 will fail to compile because the function is invalid. (*)
MYPROC1 will compile and execute successfully, except that the call to MYFUN
C1 will be treated as a comment and ignored.
Correct
SELECT upd_dept(80)
FROM dual;
Correct
They can do the same job as built-in system functions such as UPPER and ROUN
D. (*)
They can often be used inside SQL statements.
6. You want to create a function which can be used in a SQL statement. Which
one of the following can be coded within your function? Mark for Review
(1) Points
RETURN BOOLEAN
One or more IN parameters (*)
An OUT parameter
COMMIT;
3. Which of the following will display how many objects of each type are in a
user's schema? Mark for Review
(1) Points
SELECT COUNT(*)
FROM user_objects;
DESCRIBE user_objects
GROUP BY object_type;
4. You have forgotten the name of the Dictionary view USER_TABLES. Which of t
he following statements is the best and quickest way to remind yourself? Mark
for Review
(1) Points
SELECT * FROM dictionary
WHERE table_name LIKE USER%;
Correct
Correct
6. User BOB is not a database administrator. BOB wants to see the names of al
l the tables in his schema, as well as all the tables in other users' schemas wh
ich he has privileges to use. Which Data Dictionary view would BOB query to do t
his? Mark for Review
(1) Points
USER_TABLES
ALL_TABLES (*)
DBA_TABLES
USER_TAB_COLUMNS
None of the above.
7. Which of the following is NOT a benefit of the Data Dictionary? Mark for
Review
(1) Points
It allows us to remind ourselves of the names of our tables, in case we have
fogotten them.
It allows us to check which system privileges have been granted to us.
It will speed up the execution of SELECT statements in which the WHERE claus
e column is not indexed. (*)
It allows the PL/SQL compiler to check for object existence; for example, wh
en creating a procedure which references a table, the PL/SQL compiler can check
that the table exists.
8. Which of the following best describes the Data Dictionary? Mark for Revi
ew
(1) Points
It is a set of tables which can be updated by any user who has the necessary
privileges.
It is an automatically managed master catalog of all the objects stored in t
he database. (*)
It contains a backup copy of all the data in the database.
It contains a list of all database tables which are not in any schema.
1. The database administrator has granted the DROP ANY PROCEDURE privilege to u
ser KIM. This allows Kim to remove other users' procedures and functions from th
e database. How would Kim now drop function GET_EMP, which is owned by user MEHM
ET? Mark for Review
(1) Points
DROP FUNCTION get_emp FROM mehmet
DROP FUNCTION mehmet.get_emp (*)
DROP PROCEDURE mehmet.get_emp
DROP PROGRAM mehmet.get_emp
None of the above
2. You need to remove procedure BADPROC from your schema. What is the correct
syntax to do this? Mark for Review
(1) Points
DELETE PROCEDURE badproc;
DROP PROGRAM badproc;
ALTER PROCEDURE badproc DISABLE;
DROP PROCEDURE badproc; (*)
5. Which view would you query to see the detailed code of a procedure? Mark
for Review
(1) Points
user_source (*)
user_procedures
user_objects
user_dependencies
user_errors
Incorrect. Refer to Section 9 Lesson 4.
6. Which dictionary view will list all the PL/SQL subprograms in your schema?
Mark for Review
(1) Points
user_source
user_procedures
user_objects (*)
user_dependencies
user_subprograms
Correct
1. User SVETLANA creates a view called EMP_VIEW that is based on a SELECT from
her EMPLOYEES table. Svetlana now wants user PHIL to be able to query the view.
What is the smallest set of object privileges that Svetlana must grant to Phil?
Mark for Review
(1) Points
SELECT on EMP_VIEW and SELECT on EMPLOYEES
SELECT and EXECUTE on EMP_VIEW
SELECT on EMP_VIEW (*)
SELECT on EMP_VIEW and REFERENCES on EMPLOYEES
3. User TOM needs to grant both SELECT and INSERT privileges on both his EMPL
OYEES and DEPARTMENTS tables to both DICK and HARRY. What is the smallest number
of GRANT statements needed to do this? Mark for Review
(1) Points
1
2 (*)
3
4
8
4. User COLLEEN owns an EMPLOYEES table and wants to allow user AYSE to creat
e indexes on the table. Which object privilege must Colleen grant to Ayse? Mar
k for Review
(1) Points
SELECT on EMPLOYEES
INDEX on EMPLOYEES (*)
ALTER on EMPLOYEES
CREATE on EMPLOYEES
None of the above
5. User DIANE owns a DEPARTMENTS table. User JOEL needs to update the locatio
n_id column of Diane's table, but no other columns. Which SQL statement should D
iane execute to allow this? Mark for Review
(1) Points
GRANT UPDATE ON departments TO joel;
GRANT UPDATE ON departments(location_id) TO joel;
GRANT UPDATE ON departments.location_id TO joel;
GRANT UPDATE(location_id) ON departments TO joel; (*)
GRANT UPDATE ON location_id OF departments TO joel;
6. User FRED creates a procedure called DEL_DEPT using Definer's Rights, whic
h deletes a row from Fred's DEPARTMENTS table. What privilege(s) will user BOB n
eed to be able to execute Fred's procedure? Mark for Review
(1) Points
EXECUTE on DEL_DEPT (*)
EXECUTE on DEL_DEPT and DELETE on DEPARTMENTS
EXECUTE on DEL_DEPT and DELETE on FRED.DEPARTMENTS
DELETE on FRED.DEPARTMENTS
Correct
1. Users SYS (the DBA), TOM, DICK and HARRY each have an EMPLOYEES table in the
ir schemas. SYS creates a procedure DICK.SEL_EMP using Invoker's Rights which co
ntains the following code:
SELECT ... FROM EMPLOYEES ... ;
HARRY now executes the procedure. Which employees table will be queried?
Mark for Review
(1) Points
SYS.EMPLOYEES
DICK.EMPLOYEES
HARRY.EMPLOYEES (*)
None of the above
Correct
3. User SALLY's schema contains a NEWEMP table. Sally uses Invoker's rights t
o create procedure GET_NEWEMP which includes the line:
SELECT ... FROM NEWEMP ... ;
Sally also grants EXECUTE privilege on the procedure to CURLY, but no other priv
ileges. What will happen when Curly executes the procedure?
Mark for Review
(1) Points
The procedure will execute successfully.
The procedure will fail because Curly does not have SELECT privilege on NEWE
MP.
The procedure will fail because there is no NEWEMP table in Curly's schema.
(*)
The procedure will fail because Curly does not have the EXECUTE ANY PROCEDUR
E system privilege.
Correct
4. When using Invoker's rights, the invoker needs privileges on the database
objects referenced within the subprogram, as well as GRANT privilege on the proc
edure. True or False? Mark for Review
(1) Points
True
False (*)
Correct
5. Procedure GET_EMPS includes a SELECT ... FROM EMPLOYEES. The procedure was
created using Invoker's Rights. Which of the following statements are true? (Ch
oose three.) Mark for Review
(1) Points
(Choose all correct answers)
The user who executes the procedure needs EXECUTE privilege on the procedur
e. (*)
The creator of the procedure needs SELECT privilege on EMPLOYEES. (*)
The user who executes the procedure does not need any privileges.
The user who executes the procedure needs SELECT privilege on EMPLOYEES. (*
)
Correct
Section 10
Quiz: Creating Packages
1. Package EMP_PACK contains two procedures, DEL_EMP and SHOW_EMP. You want to
write an anonymous block which invokes these procedures but you have forgotten w
hich parameters they use. Which of the following will give you this information?
Mark for Review
(1) Points
DESCRIBE del_emp
DESCRIBE show_emp
DESCRIBE emp_pack
(*)
DESCRIBE emp_pack.del_emp
DESCRIBE emp_pack.show_emp
Correct
3. Which of the following are good reasons to group a set of procedures and f
unctions into a package? Mark for Review
(1) Points
Application developers do not need to know the details of the package body c
ode.
Related subprograms and variables can be grouped together for easier managem
ent and maintenance.
If the detailed code is changed, aplications which invoke the package do not
need to be recompiled.
All of the above. (*)
Correct
5. The two parts of a package are stored as separate objects in the database.
True or False? Mark for Review
(1) Points
True (*)
False
BEGIN
dept_pack.get_dept(20);
END;
DECLARE
v_deptname VARCHAR2(20);
BEGIN
v_deptname := get_dept(50);
END;
BEGIN
dept_pack(30);
END;
Correct
3. Your schema contains a package called EMP_PKG. You want to remove the pack
age body but not the specification. The correct syntax to do this is: DROP BODY
emp_pkg; True or False? Mark for Review
(1) Points
True
False (*)
Correct
False
8. Which one of the following queries would you use to see the detailed code
of a package called EMP_PKG? Mark for Review
(1) Points
SELECT text
FROM user_source
WHERE name = 'EMP_PKG' AND type = 'PACKAGE'
ORDER BY line;
SELECT source
FROM user_packages
WHERE name = 'EMP_PKG' AND type = 'PACKAGE BODY'
ORDER BY line;
SELECT text
FROM all_source
WHERE name = 'EMP_PKG' AND type = 'PACKAGE'
ORDER BY line;
SELECT text
FROM user_source
WHERE name = 'EMP_PKG' AND type = 'PACKAGE BODY'
ORDER BY line;
(*)
The package will not compile because you cannot declare variables in the sp
ecification, only procedures and functions. .
10. We want to remove both the specification and the body of package CO_PACK
from the database. Which of the following commands will do this? Mark for Revi
ew
(1) Points
DROP BOTH co_pack;
DROP PACKAGE BODY co_pack;
DROP PACKAGE co_pack; (*)
DROP PACKAGE SPECIFICATION co_pack;
None of the above
2. When using a package function in DML statements, which rules must you foll
ow? (Choose three) Mark for Review
(1) Points
(Choose all correct answers)
Must not end the current transaction (*)
Can read or modify the table being changed by that DML statement
Changes to a package variable could have an impact on another stored functi
on (*)
Cannot execute a DML statement or modify the database (*)
Incorrect. Refer to Section 10 Lesson 3.
3. The package name must be included when calling a package function from a S
ELECT statement executed outside the package. True or False? Mark for Review
(1) Points
True (*)
False
Correct
4. INDEX BY is missing from this package declaration. What is the most effici
ent declaration?
CREATE OR REPLACE PACKAGE emp_pkg IS
TYPE emp_tab IS TABLE OF employees%ROWTYPE;
PROCEDURE get_employees(p_emp_table OUT emp_tab);
END emp_pkg;
Mark for Review
(1) Points
INDEX BY INTEGER
INDEX BY BINARY
INDEX BY BINARY_INTEGER (*)
INDEX ALL
Correct
Correct
8. How would you invoke the constant km_to_mile from the global_consts bodile
ss package at VARIABLE A?
SELECT trail_name, distance_in_km * VARIABLE A
FROM trails
WHERE park_name = 'YOSEMITE';
Mark for Review
(1) Points
km_to_mile.global_consts
km_to_mile (global_consts)
global_consts.km_to_mile (*)
global_consts (km_to_mile)
Correct
Correct
12. Package FORWARD_PACK contains two procedures: PROC1 is public while PROC2
is private (not declared in the package specification). These procedures have n
o parameters. Which of the following package bodies will NOT compile successfull
y? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)
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;
(*)
14. The following example package specification is valid to create a data typ
e ed_type that can be used in other subprograms. True or False?
CREATE OR REPLACE PACKAGE emp_dept_pkg IS
TYPE ed_type IS RECORD (f_name employees.first_name%TYPE,
l_name employees.last_name%TYPE,
d_name departments.department_name%TYPE);
PROCEDURE sel_emp_dept
(p_emp_id IN employees.employee_id%TYPE,
p_emp_dept_rec OUT ed_type);
END emp_dept_pkg;
Mark for Review
(1) Points
True (*)
False
Correct
Section 11
Quiz: Persistant State of Package Variables
Correct
2. The UTL_FILE package can be used to read and write binary files such as JP
EGs as well as text files. True or False? Mark for Review
(1) Points
True
False (*)
5. Using the FOPEN function, you can do which actions with the UTL_FILE packa
ge? (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 find out how much free space is left on an operating system d
isk.
It is used to manipulate large object data type items in columns.
6. Which DBMS_OUTPUT package subprogram places text into the buffer at Line 1
? (Choose one)
IF v_bool1 AND NOT v_bool2 AND v_number < 25 THEN
--Line 1
ELSE
...
END IF;
DBMS_OUTPUT.NEW_LINE;
Mark for Review
(1) Points
DBMS_OUTPUT.PUT('IF branch was executed'); (*)
DBMS_OUTPUT.PUT_LINE('IF branch was executed');
DBMS_OUTPUT.GET_LINE('IF branch was executed');
DBMS_OUTPUT.NEW_LINE('IF branch was executed');
Correct
Section 12
1. Name two reasons for using Dynamic SQL. Mark for Review
(1) Points
(Choose all correct answers)
Avoid errrors at compile time of DML statements.
Correct
2. What happens when a SQL statement is parsed? (Choose three.) Mark for Re
view
(1) Points
(Choose all correct answers)
The user's required privileges are checked. (*)
The syntax of the statement is checked. (*)
3. For which of the following is it necessary to use Dynamic SQL? (Choose thr
ee.) Mark for Review
(1) Points
(Choose all correct answers)
ALTER (*)
GRANT (*)
SAVEPOINT
UPDATE
DROP (*)
4. Examine the following procedure, which drops a table whose name is passed
as an IN parameter:
CREATE OR REPLACE PROCEDURE drop_tab
(p_table_name IN VARCHAR2) IS
v_sql_statement VARCHAR2(100);
BEGIN
...
END;
Which of the following will work correctly when coded in the procedure's executa
ble section? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)
EXECUTE IMMEDIATE 'DROP TABLE p_table_name';
Correct
5. When SQL statements are included within a procedure, the statements are pa
rsed when the procedure is compiled. True or False? Mark for Review
(1) Points
True (*)
False
Correct
6. The DBMS_SQL package is easier to use than EXECUTE IMMEDIATE. True or Fals
e? Mark for Review
(1) Points
True
False (*)
9. Only one call to DBMS_SQL is needed in order to drop a table. True or Fals
e? Mark for Review
(1) Points
True
False (*)
Correct
Correct
3. What is the main purpose for using the RETURNING clause? Mark for Review
(1) Points
Improve performance by returning a single value.
Improve performance by minimizing the number of statements.
Improve performance by making one call to the SQL engine. (*)
Return more readily any exceptions that are raised by the statement.
4. In the following example, where do you place the phrase BULK COLLECT?
...
BEGIN
SELECT -- Position A
salary -- Position B
INTO v_saltab -- Position C
FROM employees WHERE department_id = 20 ORDER BY salary
-- Position D
;
...
Mark for Review
(1) Points
Position A
Position B (*)
Position C
Position D
Correct
5. In the following example, where do you place the phrase BULK COLLECT?
DECLARE
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;
Mark for Review
(1) Points
Position A
Position B (*)
Position C
Correct
6. FORALL can only be used with the INSERT statement. True or False? Mark f
or Review
(1) Points
True
False (*)
Correct
8. What are benefits of using the NOCOPY hint? (Choose two) Mark for Review
(1) Points
(Choose all correct answers)
Safer because it uses passing by value.
Efficient since it uses less memory. (*)
Uses a larger block of server memory for faster access.
Faster because a single copy of the data is used. (*)
9. A function-based index may be made using your own functions, but only if t
he function is created using the DETERMINISTIC clause. True or False? Mark for
Review
(1) Points
True (*)
False
Correct
10. The following statement is a valid example of using the RETURNING clause.
True or False?
DECLARE
TYPE EmpRec IS RECORD (last_name employees.last_name%TYPE, salary employees.s
alary%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;
Mark for Review
(1) Points
True (*)
False
Section 13
Quiz: Introduction to Triggers
1. Which of the following could NOT be done by a database trigger? Mark for R
eview
(1) Points
Enforcing a complex business rule
Enforcing a complex database security check
Recalculating the total salary bill for a department whenever an employee's
salary is changed
Ensuring that a student never arrives late for a class (*)
Keeping a log of how many rows have been inserted into a table
2. 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 trigger. True or False? Mark for Review
(1) Points
True
False (*)
Correct
3. While editing a document in Microsoft Word, you go to the FILE menu and SA
VE your work. To do this, Microsoft Word has executed an application trigger. Tr
ue or False? Mark for Review
(1) Points
True (*)
False
Correct
5. You can use a database trigger to prevent invalid transactions from being
committed. True or False? Mark for Review
(1) Points
True (*)
False
Correct
6. Which of the following are NOT allowed within a database trigger? (Choose
two) Mark for Review
(1) Points
(Choose all correct answers)
COMMIT (*)
A call to a packaged procedure
INSERT
A Boolean variable
SAVEPOINT (*)
7. Which of the following best describes a database trigger? Mark for Revie
w
(1) Points
Correct
10. Which of the following are good guidelines to follow when creating trigge
rs? (Choose two) Mark for Review
(1) Points
(Choose all correct answers)
Be aware of recursive and cascading effects (*)
Where possible, use triggers to enforce NOT NULL constraints
Avoid lengthy trigger logic by creating a procedure and invoking it from wi
thin the trigger (*)
Use triggers to replace functionality which is already built into the datab
ase
Always create more triggers than you need, because it is better to be safe
2. A BEFORE statement trigger inserts a row into a logging table every time a
user updates the salary column of the employees table. The user now tries to up
date the salaries of three employees with a single UPDATE statement, but the upd
ate fails because it violates a check constraint. How many rows will be inserted
into the logging table? Mark for Review
(1) Points
None, the transactions are rolled back because the update failed. (*)
One
Three
Four
None of the above
3. Which of the following is the correct syntax for creating a DML trigger as
sociated with the EMPLOYEES table? The trigger must fire whenever an employee's
JOB_ID is updated, but not if a different column is updated. Mark for Review
(1) Points
CREATE TRIGGER job_upd_trigg
AFTER UPDATE ON employees(job_id)
BEGIN ...
4. Which of the following are possible keywords for the timing component of a
trigger? (Choose three.) Mark for Review
(1) Points
(Choose all correct answers)
BEFORE (*)
INSTEAD
WHENEVER
INSTEAD OF (*)
AFTER (*)
Six times, once after each row and once at the end of the statement
The trigger will not fire at all
7. We want to create a log record automatically every time any DML operation
is executed on either or both of the EMPLOYEES and DEPARTMENTS tables. What is t
he smallest number of triggers that must be create to do this? Mark for Review
(1) Points
One
Two (*)
Three
Six
Eight
8. An AFTER UPDATE trigger can specify more than one column. True or False?
Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 13 Lesson 2.
3. 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 (*)
Twice
Four times (*)
Five times
Eight times
7. Which of the following statements about INSTEAD OF triggers are NOT true?
(Choose two.) Mark for Review
(1) Points
(Choose all correct answers)
They can be created on a table. (*)
They can be created on a simple view.
They can be created on a complex view.
They can be statement triggers. (*)
They can be row triggers.
8. Examine the following code. To create a row trigger, what code should be i
ncluded at Line A?
CREATE OR REPLACE TRIGGER del_emp_trigg
BEFORE DELETE ON employees
---- Line A
BEGIN ...
Mark for Review
(1) Points
FOR EVERY ROW
FOR EACH ROW (*)
FOR EVERY ROW
FOR ALL ROWS
Nothing is needed because DML triggers are row triggers by default.
10. What are the timing events for a compound trigger? Mark for Review
(1) Points
Before the triggering statement; After the triggering statement; Instead of
the triggering statement.
Before the triggering statement; Before each row; After each row; After the
triggering statement. (*)
Before the triggering statement; After the triggering statement; After each
row.
Before the triggering statement; Before each row; After the triggering state
ment
1. You can create a trigger which prevents DDL statements on an individual tabl
e, while still allowing DDL on other tables in the same schema. True or False?
Mark for Review
(1) Points
True
False (*)
Correct
Correct
4. You have been granted CREATE TRIGGER privilege. You can now create an AFTE
R LOGOFF ON SCHEMA trigger. True or False? Mark for Review
(1) Points
True
False (*)
5. Mutating table errors can be caused by DML triggers, but not by database e
vent triggers. True or False? Mark for Review
(1) Points
True (*)
False
Correct
6. 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 trigg
er.
It prevents data being read from a mutating table.
It allows the database administrator to monitor who is currently connected t
o the database.
It allows the trigger body code to be placed in a separate procedure. (*)
7. Which of the following could NOT cause a DDL or Database Event trigger to
fire? Mark for Review
(1) Points
A table is dropped.
A user connects to the database.
The DBA starts up the database.
A user deletes rows from the EMPLOYEES table. (*)
A specific exception is raised in a user's session.
Incorrect. Refer to Section 13 Lesson 4.
8. The database administrator wants to write a log record every time any user
's session raises an ORA-00942 exception. The DBA decides to create the followin
g trigger:
CREATE OR REPLACE TRIGGER log_942_trigg
AFTER SERVERERROR ON DATABASE
BEGIN
-- Line A
INSERT INTO log_table VALUES ( ...);
END;
What should the DBA code at Line A?
Mark for Review
(1) Points
IF (SERVERERROR(942)) THEN
IF (IS_SERVERERROR(942)) THEN (*)
9. User HARJIT wants to prevent any objects which he owns from being dropped.
Harjit decides to execute the following code:
CREATE OR REPLACE TRIGGER stop_drop
---- Line A
BEGIN
RAISE_APPLICATION_ERROR(-20201,'Attempted drop');
END;
What should Harjit code at Line A?
Mark for Review
(1) Points
BEFORE DROP ON HARJIT
1. You have created several DML triggers which reference your DEPARTMENTS tab
le. Now you want to disable all of them using a single SQL statement. Which comm
and should you use? Mark for Review
(1) Points
ALTER TRIGGER DISABLE ALL ON departments;
ALTER TABLE departments DISABLE ALL TRIGGERS; (*)
ALTER TABLE departments DISABLE TRIGGERS;
DROP ALL TRIGGERS ON departments;
Correct
2. Which dictionary view would you query to see the detailed body code of tri
ggers in your schema? Mark for Review
(1) Points
USER_SOURCE
USER_TRIGGER
USER_TRIGGERS (*)
USER_OBJECTS
None of the above, you cannot view the code of the trigger body after the tr
igger has been created.
4. User KULJIT creates two triggers named EMP1_TRIGG and EMP2_TRIGG, which ar
e both DML triggers referencing her EMPLOYEES table. Kuljit now wants to remove
both of these triggers from the database. What command(s) should Kuljit use to d
o this? Mark for Review
(1) Points
DROP ALL TRIGGERS ON employees;
5. Which command would you use to see if your triggers are enabled or disable
d? Mark for Review
(1) Points
SELECT trigger_name, status
FROM USER_TRIGGERS;
(*)
DESCRIBE TRIGGER
6. By default, any user can create a DML trigger on a table in his/her schema
. True or False? Mark for Review
(1) Points
True
False (*)
Section 14
1. Which of the following will NOT help to minimize dependency failures? (Choos
e two.) Mark for Review
(1) Points
(Choose all correct answers)
SELECTing a list of column names instead of using SELECT * (*)
Declaring records using the %ROWTYPE attribute
Including a column list with INSERT statements
Declaring scalar variables with NOT NULL if the corresponding table column
has a NOT NULL constraint (*)
Declaring scalar variables using the %TYPE attribute
Correct
3. Procedure get_depts has been marked invalid because one of the objects it
references has been altered. Which of the following statements are true? (Choose
two.) Mark for Review
(1) Points
(Choose all correct answers)
The procedure will be recompiled automatically the next time it is invoked.
The recompilation will always be successful.
4. The IDEPTREE view shows dependencies by indenting the lines of output inst
ead of by using a NESTED_LEVEL column. True or False? Mark for Review
(1) Points
True (*)
False
Correct
BEGIN deptree_fill('PROCEDURE','ALICE','SHOW_EMPS');
END;
BEGIN deptree_fill('ALICE','TABLE','EMPLOYEES');
END;
BEGIN deptree_fill('TABLE','ALICE','EMPLOYEES');
END;
(*)
BEGIN deptree_fill('ALICE','PROCEDURE','SHOW_EMPS');
END;
6. Which data dictionary view shows information about references and dependen
cies? Mark for Review
(1) Points
DEPTREE
USER_DEPENDENCIES (*)
USER_REFERENCES
USER_LOCAL_DEPENDENCIES
Correct
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.
10. Which of the following statements will show whether procedure myproc is v
alid or invalid? Mark for Review
(1) Points
SELECT status FROM USER_OBJECTS
WHERE object_type = 'PROCEDURE'
AND object_name = 'MYPROC';
(*)
13. Which of the following database objects are created when the utldtree.sql
script is run? (Choose three.) Mark for Review
(1) Points
(Choose all correct answers)
The utldtree table
The deptree_temptab table (*)
The deptree and ideptree views (*)
The deptree table
The deptree_fill procedure (*)
14. View dept_view is based on a select from table departments. Procedure sho
w_dept contains code which selects from dept_view. Which of the following statem
ents are true? (Choose three.) Mark for Review
(1) Points
(Choose all correct answers)
departments is indirectly dependent on show_dept
Correct
Correct
3. In Signature Mode, a procedure will not compile if the signatures of the r
emote dependencies do not match. True or False? Mark for Review
(1) Points
True (*)
False
Correct
6. Which statement for setting a database parameter is the default for remote
dependency checking? Mark for Review
(1) Points
ALTER SESSION SET REMOTE_DEPENDENCIES_MODE = TIMESTAMP (*)
ALTER SESSION SET REMOTE_DEPENDENCIES_MODE = SIGNATURE
ALTER SESSION REMOTE_DEPENDENCIES_MODE = TIMESTAMP
ALTER SESSION REMOTE_DEPENDENCIES_MODE = SIGNATURE
Correct
8. The Data Dictionary controls the remote dependency mode. True or False?
Mark for Review
(1) Points
True
False (*)
Section 15
1. Which data dictionary view allows you to see the setting for PLSQL_OPTIMIZE_
LEVEL? Mark for Review
(1) Points
USER_PLSQL_OBJECTS
USER_PLSQL_OPTIMIZE
USER_PLSQL_OBJECT_SETTINGS (*)
USER_OBJECT_SETTINGS
USER_PLSQL_CODE_TYPE
Correct
3. What are the valid values for PLSQL_OPTIMIZE_LEVEL in the data dictionary?
Mark for Review
(1) Points
0,1,2,3 (*)
0,1,2,3,4
1,2,3
1,2,3,4
4. PLSQL_CODE_TYPE determines the type of code for PL/SQL code and for SQL st
atements, which is what speeds up the execution speed. True or False? Mark for
Review
(1) Points
True
False (*)
Correct
Correct
Correct
Correct
3. A warning in PL/SQL is the same as an error in PL/SQL, but can only be vie
wed through the USER_ERRORS data dictionary view. True or False? Mark for Revi
ew
(1) Points
True
False (*)
4. Which PL/SQL warning message identifies code that can cause unexpected beh
aviour or wrong results when executed? Mark for Review
(1) Points
INFORMATIONAL
PERFORMANCE
ALL
SEVERE (*)
ERROR
5. Which pair of DBMS_WARNING commands would allow you to obtain the current
settings and change and restore those settings in a PL/SQL subprogram? (Choose t
wo) Mark for Review
(1) Points
(Choose all correct answers)
DBMS_WARNING.SET_WARNING_SETTING_STRING (*)
DBMS_WARNING.ADD_WARNING_SETTING_CAT
DBMS_WARNING.GET_WARNING_SETTING_STRING (*)
DBMS_WARNING.GET_WARNING_STRING
Correct
6. 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
$$IF
$$THEN
$$ELSE
$$ELSIF
$$END
$IF
$THEN
$ELSE $ELSIF
$ENDIF
$IF
$THEN
$ELSE
$ELSIF
$END
(*)
$$IF
$$THEN
$$ELSE
$$END
$$DEBUG
Correct
4. Conditional compilation allows you to include extra code to help with debu
gging, which can be removed once errors are resolved. True or False? Mark for
Review
(1) Points
True (*)
False
Correct
6. You can choose which code to include in a PL/SQL program based on conditio
nal compilation directives. True or False? Mark for Review
(1) Points
True (*)
False
Correct
Correct
2. For PL/SQL code larger than 32,767 characters, you must use the wrap utili
ty. True or False? Mark for Review
(1) Points
True (*)
False
DBMS_DDL.WRAP_CODE
4. To create obfuscated code using the wrapper utility, determine the order i
n which to execute the following steps.
A Connect to the database and execute the wrapped text file as a script to comp
ile the wrapped code into the Data Dictionary.
B Log into the database server computer.
C Create a text file containing your complete unwrapped source code.
D Execute WRAP to create a second text file containing the wrapped code.
Mark for Review
(1) Points
A,B,C,D
B,C,D,A (*)
C,D,A,B
C,A,B,D
B,D,C,A
Correct
5. Obfuscation allows the owner to see the source code, but not the users to
whom EXECUTE privileges have been granted. True or False? Mark for Review
(1) Points
True
False (*)
Correct
Correct