Midterm Exam
Midterm Exam
(1) Points
Both the specification and the body will be dropped. (*)
The body will be dropped but the specification will be retained.
The specification will be dropped but the body will be retained.
The statement will fail because you must drop the body before you can drop
the specification.
Correct
2. A local variable defined inside a package procedure is visible to the calling
environment. True or False?
Mark for Review
(1) Points
True
False (*)
Correct
(1) Points
True
False (*)
Correct
(1) Points
True (*)
False
Correct
(1) Points
emp_pkg.emp_sal(101);
None of these.
scott.emp_pkg.emp_sal(101): (*)
emp_sal(101);
All of these.
Correct
6. We need to declare a package variable named MYVAR, which can be
referenced by any subprogram in the package but can NOT be referenced
from outside the package. In the following code, where should MYVAR be
declared?
CREATE OR REPLACE PACKAGE varpack IS
-- Point A
...
END varpack;
CREATE OR REPLACE PACKAGE BODY varpack IS
-- Point B
PROCEDURE varproc IS
-- Point C
BEGIN
...
END varproc;
PROCEDURE ...
...
-- Point D
END varpack;
(1) Points
Point C
Point D
Point B (*)
Point B or Point C, they will both work
Point A
Correct
(1) Points
The detailed code of all packages in the user's schema
The parameters which must be used when invoking all packaged
subprograms in the user's schema
The names of all package specifications and package bodies in the user's
schema (*)
The names of all package specifications in the user's schema
The names of all packages which can be invoked by the user
Correct
8. We want to remove the specification (but not the body) of package
BIGPACK from the database. Which of the following commands will do this?
Mark for Review
(1) Points
DROP PACKAGE HEADER bigpack;
DROP PACKAGE SPECIFICATION bigpack;
DROP PACKAGE bigpack SPECIFICATION;
None of these. (*)
DROP PACKAGE bigpack;
Correct
(1) Points
From any function in NEWPACK (*)
From any procedure in NEWPACK (*)
From any private function in another package
From an anonymous block
From any public procedure in another package
Correct
(1) Points
True
False (*)
Correct
Previous
11. Package TAXPACK declares a global variable G_TAXRATE NUMBER(2,2).
The value of the tax rate is stored in table TAXTAB in the database. You
want to read this value automatically into G_TAXRATE each time a user
session makes its first call to TAXPACK. How would you do this?
Mark for Review
(1) Points
Declare the global variable as:
g_taxrate NUMBER(2,2) := SELECT tax_rate FROM taxtab;
Create a database trigger that includes the following code:
SELECT tax_rate INTO taxpack.g_taxrate FROM taxtab;
Add a private function to the package body of TAXPACK, and invoke the
function from the user session.
Add a package initialization block to the package body of TAXPACK. (*)
Correct
(1) Points
FUNCTION sal_ok(pf_salary NUMBER) RETURN BOOLEAN; (*)
FUNCTION sal_ok;
FUNCTION sal_ok(pf_salary NUMBER);
Nothing is needed at Line A
PROCEDURE upd_emp (p_empno IN NUMBER, p_salary IN NUMBER);
Correct
13. Suppose you want to automatically execute some code every time you
make the first call to a package in your session? For example, you want to
automatically load a tax rate into a package variable.
Which of the following should you use?
Mark for Review
(1) Points
package initialization block (*)
None of these.
forward declaration
bodiless package
Correct
(1) Points
INDEX BY BINARY_INTEGER (*)
INDEX BY INTEGER
INDEX ALL
INDEX BY BINARY
Correct
15. How would you invoke the constant mile_to_km from the global_consts
bodiless package at VARIABLE A?
DECLARE
distance_in_miles NUMBER(5) := 5000;
distance_in_km NUMBER(6,2);
BEGIN
distance_in_km :=
distance_in_miles * VARIABLE A;
DBMS_OUTPUT.PUT_LINE(distance_in_km);
END;
(1) Points
global_consts.mile_to_km (*)
global_consts (mile_to_km)
mile_to_km (global_consts)
mile_to_km.global_consts
Correct
Previous
16. The following call to the function tax in the taxes_pkg package is invalid
for what reason?
(1) Points
The call to the function should be taxes_pkg.tax_salary.
The data type of tax does not match that of salary.
The call to the function should be taxes_pkg (tax.salary).
The call to the package is valid and will execute without error. (*)
Correct
(1) Points
Procedures only
Public variables only (*)
Private variables only
Functions only
Incorrect. Refer to Section 10 Lesson 3.
18. When using a package function in DML statements, which rules must you
follow? (Choose three)
Mark for Review
(1) Points
Can read or modify the table being changed by that DML statement
Cannot execute a DML statement or modify the database (*)
Changes to a package variable could have an impact on another stored
function (*)
Must not end the current transaction (*)
Correct
(1) Points
It is a private function within the package body.
Because it is an anonymous block, it cannot be invoked and therefore will
never execute. It is treated as a set of comments.
It is an anonymous block in the package specification.
It is an anonymous block at the end of a package body which executes
automatically the first time each user session invokes a subprogram in the
package. (*)
It is a named procedure in a package which must be invoked by a user
before any other part of the package can be invoked.
Correct
(1) Points
True (*)
False
Correct
Previous
21. 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 (*)
Correct
(1) Points
True (*)
False
Correct
(1) Points
Application developers do not need to know the details of the package body
code.
All of these. (*)
Related subprograms and variables can be grouped together for easier
management and maintenance.
If the detailed code is changed, applications which invoke the package do
not need to be recompiled.
Correct
(1) Points
True (*)
False
Incorrect. Refer to Section 10 Lesson 1.
(1) Points
The specification and body must be created at the same time.
It does not matter which is created first.
The body
The body can be created first, but only if the package has no specification.
The specification (*)
Correct
Previous
26. Which of the following can be included in a package?
Mark for Review
(1) Points
Exceptions
procedures
PL/SQL types
All of these. (*)
variables
Correct
(1) Points
Body
Specification
Body and the specification (*)
None of these.
Correct
(1) Points
True
False (*)
Correct
Section 11
(Answer all questions in this section)
29. 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 cannot be used inside procedures
Because DBMS_OUTPUT can raise a NO_DATA_FOUND exception if used
inside a packaged procedure
Because DBMS_OUTPUT should be used only for testing and debugging
PL/SQL code (*)
Because anonymous blocks display messages while the block is executing,
while procedures do not display anything until their execution has finished
Correct
30. 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 find out how much free space is left on an operating system
disk.
It is used to query CHAR and VARCHAR2 columns in tables.
It is used to read and write text files stored outside the database. (*)
Correct
Previous
31. The UTL_FILE package can be used to read and write binary files such as
JPEGs as well as text files. True or False?
Mark for Review
(1) Points
True
False (*)
Correct
(1) Points
True (*)
False
Incorrect. Refer to Section 11 Lesson 2.
(1) Points
I do like to be
beside the seaside
I do like to be beside the seaside
I do like to be
I do like
to be
beside the seaside
I do liketo be (*)
Correct
34. Which of the following procedures is not valid for the UTL_MAIL package
Mark for Review
(1) Points
SEND
SEND_ATTACH_RAW
SEND_ATTACH_BOOLEAN (*)
All are valid.
SEND_ATTACH_VARCHAR2
Correct
(1) Points
25
50 (*)
10
Correct
Previous
36. In the following example, which statement best fits in Line 1? (Choose 1)
DECLARE
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;
(1) Points
curs_pkg.close_curs;
EXIT WHEN curs_pkg.emp_curs%NOTFOUND;
curs_pkg.emp_curs%ISOPEN;
curs_pkg.open_curs; (*)
Correct
(1) Points
True
False (*)
Correct
User HAZEL now connects to the database. Both users immediately execute:
BEGIN
DBMS_OUTPUT.PUT_LINE(multipack.g_myvar);
END;
(1) Points
Dick: 45, Hazel: 45
Dick: 45, Hazel: 0
Dick: 45, Hazel: null (*)
Dick: 0, Hazel: 0
Both queries will fail because the syntax of DBMS_OUTPUT.PUT_LINE is
incorrect
Correct
Section 12
(Answer all questions in this section)
39. 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
40. A SQL statement can pass through several stages. Which of the following
is NOT one of these stages?
Mark for Review
(1) Points
BIND
RETURN (*)
EXECUTE
PARSE
FETCH
Correct
Previous
41. 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.
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.)
(1) Points
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; (*)
42. You want to create a function which drops a table. You write the
following code:
CREATE OR REPLACE FUNCTION droptab
(p_tab_name IN VARCHAR2)
RETURN BOOLEAN IS
BEGIN
DROP TABLE p_tab_name;
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN RETURN FALSE;
END;
(1) Points
True
False (*)
Correct
(1) Points
True (*)
False
Correct
45. 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
;
...
(1) Points
Position A
Position B (*)
Position C
Position D
Correct
Previous
46. The following procedure compiles successfully. True or False?
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;
(1) Points
True
False (*)
Correct
47. FORALL can only be used with the INSERT statement. True or False?
Mark for Review
(1) Points
True
False (*)
Correct
48. 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;
(1) Points
Position A
Position B (*)
Position C
Correct
(1) Points
True (*)
False
Correct
(1) Points
Nothing is wrong; it will compile successfully.
FORALL does not require END LOOP. (*)
v_emptab is incorrectly typed.
The phrase should be FOR ALL.
Correct
Previous