Professional Documents
Culture Documents
Semester 2 Midterm Exam
Semester 2 Midterm Exam
Section 10
(Answer all questions in this section)
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
which parameters they use. Which of the following will give you this information?
DESCRIBE del_emp
DESCRIBE show_emp
DESCRIBE emp_pack.del_emp
DESCRIBE emp_pack.show_emp
None of these.
Correct
(1/1) Points
Which of the following are correct syntax for invoking the package subprograms?
(Choose two.)
BEGIN
dept_pack.ins_dept(20);
END; (*)
BEGIN
dept_pack(30);
END;
DECLARE
v_deptname VARCHAR2(20);
BEGIN
v_deptname := get_dept(50);
END;
BEGIN
dept_pack.get_dept(20);
END;
Correct
(1/1) Points
3. Which part of a package must be created first, the specification or the body?
The body
The body can be created first, but only if the package has no specification.
Correct
(1/1) Points
4. Package MYPACK contains procedure MYPROC. You can see which parameters
MYPROC uses by executing: DESCRIBE mypack.myproc. True or False?
True
False (*)
Correct
(1/1) Points
5. The two parts of a package are stored as separate objects in the database. True or
False?
True (*)
False
Correct
6. The following package specification has been created:
CREATE OR REPLACE PACKAGE mypack IS
FUNCTION myfunc(p_funcparam DATE) RETURN BOOLEAN;
PROCEDURE myproc(p_procparam IN NUMBER);
END mypack;
Which of the following will correctly invoke the package subprograms? (Choose
two.)
11. In a package, public components are declared in the specification but private
components are not. True or False?
True (*)
False
Correct
(1/1) Points
12. A local variable defined inside a package procedure is visible to the calling
environment. True or False?
True
False (*)
Correct
(1/1) Points
13. A public component declared in the package specification can be referenced
by a private component defined in the package body. True or False?
True (*)
False
Correct
(1/1) Points
14. 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 specification
and the body must be recompiled. True or False?
True
False (*)
Correct
(1/1) Points
15. 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;
Point A
Point D
Point C
Point B or Point C, they will both work
Point B (*)
Correct
The package body of TAXPACK also includes a function called TAXFUNC. Which
one of the following statements is NOT true?
global_consts.mile_to_km (*)
mile_to_km (global_consts)
mile_to_km.global_consts
global_consts (mile_to_km)
Correct
Functions only
Procedures only
Correct
(1/1) Points
27. 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?
True (*)
False
Correct
(1/1) Points
28. Which two of these functions could not be in the same package?
3 and 4
2 and 4
2 and 3 (*)
1 and 2
1 and 4
Correct
(1/1) Points
Section 11
(Answer all questions in this section)
User HAZEL now connects to the database. Both users immediately execute:
BEGIN
DBMS_OUTPUT.PUT_LINE(multipack.g_myvar);
END;
Dick: 0, Hazel: 0
Correct
(1/1) Points
30. 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 Point A?
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
25
10
50 (*)
Correct
31. A package's state is initialized when the package is first loaded. True or False?
True (*)
False
Correct
(1/1) Points
32. When a user session changes the value of a package variable, the new value
can immediately be seen by other sessions. True or False?
True
False (*)
Correct
(1/1) Points
33. Which of the following best describes the purpose of the UTL_FILE package?
It is used to read and write text files stored outside the database. (*)
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.
Correct
(1/1) Points
34. Why is it better to use DBMS_OUTPUT only in anonymous blocks, not inside
stored subprograms such as procedures?
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
Because DBMS_OUTPUT cannot be used inside procedures
Because DBMS_OUTPUT can raise a NO_DATA_FOUND exception if used inside a
packaged procedure
Correct
(1/1) Points
35. The UTL_FILE package contains several exceptions exclusively used in this
package. Which are they? (Choose 3)
(Choose all correct answers)
ZERO_DIVIDE
INVALID_OPERATION (*)
INVALID_PATH (*)
WRITE_ERROR (*)
NO_DATA_FOUND
Correct
36. The UTL_FILE package can be used to create binary files such as JPEGs as well as text
files. True or False?
True
False (*)
(0/1) Points
37. The DBMS_OUTPUT package is useful for which of the following activities? (Choose
two)
Display results to the developer during testing for debugging purposes (*)
Correct
(1/1) Points
38. 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
branch of an IF statement. (True or False?)
True (*)
False
Correct
(1/1) Points
Section 12
(Answer all questions in this section)
39. The easiest way to include DDL statements in a PL/SQL block is to use the DBMS_SQL
package. True or False?
True
False (*)
Correct
(1/1) Points
40. A SQL statement can pass through several stages. Which of the following is NOT one
of these stages?
PARSE
EXECUTE
BIND
FETCH
RETURN (*)
Correct
Position A
Position B (*)
Position C
Correct
46. 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 this
efficiently. True or False?
CREATE OR REPLACE PROCEDURE copy_cities IS
TYPE t_cities IS TABLE OF cities%ROWTYPE INDEX BY BINARY_INTEGER;
v_citiestab t_cities;
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
(1/1) Points
47. What does the RETURNING clause do in the example below?
CREATE OR REPLACE PROCEDURE new_dept
(p_dept_name IN departments.name%TYPE) IS
v_new_dept_id departments.dept_id%TYPE;
BEGIN
INSERT INTO departments (dept_id, name)
VALUES dept_seq.NEXTVAL, p_dept_name
RETURNING dept_seq.CURRVAL INTO v_new_dept_id;
DBMS_OUTPUT.PUT_LINE(p_dept_name ||' is department number ' ||
v_new_dept_id);
END new_dept;
True (*)
False
Correct
(1/1) Points
49. 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.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
(1/1) Points
50. What is wrong with this code example?
CREATE OR REPLACE PROCEDURE insert_emps IS
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;