Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Test: PL/SQL Database Programming 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.

DESCRIBE emp_pack(del_emp, show_emp)

DESCRIBE emp_pack (*)

Correct

(1/1) Points

2. Package Specification DEPT_PACK was 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.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;

CREATE PROCEDURE dept_proc IS


v_deptname VARCHAR2(20);
BEGIN
v_deptname := dept_pack.get_dept(40);
END; (*)

Correct

(1/1) Points

3. Which part of a package must be created first, the specification or the body?

The body

The specification and body must be created at the same time.

The body can be created first, but only if the package has no specification.

It does not matter which is created first.

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

(Choose all correct answers)


IF NOT mypack.myfunc(SYSDATE) THEN
DBMS_OUTPUT.PUT_LINE('Message');
END IF; (*)
mypack.myfunc('22-Jan-2007');
myproc(40);
mypack.myproc(35); (*)
v_num := mypack.myproc(22);
Correct
(1/1) Points
7. Which one of the following can NOT be part of a Package ?
Global variables
Explicit cursors
Functions
Triggers (*)
Procedures
Correct
(1/1) Points
8. In which component of a package is the full definition of a public procedure
written?
Body (*)
Both the body and the specification
Specification
Neither the body nor the specification
Correct
(1/1) Points
9. Package OLDPACK is in your schema. What will happen when the following
statement is executed?
DROP PACKAGE oldpack;

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.
Both the specification and the body will be dropped. (*)
Correct
(1/1) Points
10. A package contains both public and private subprograms. Which one of the
following statements is true?
The whole package is loaded into memory when the first call is made to any
subprogram in the package. (*)
If three users invoke three different subprograms in the package, there will be
three copies of the code in memory.
Each subprogram is loaded into memory when it is first invoked.
The public subprograms are all loaded into memory at the same time, but the
private subprograms are loaded into memory one at a time as they are invoked.
Correct

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

16. Examine the following package specification:


CREATE OR REPLACE PACKAGE taxpack IS
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?

TAXPROC can open the cursor.


TAXPROC can invoke TAXFUNC if TAXPROC is coded before TAXFUNC.
The procedure can be invoked by:
BEGIN
taxpack.taxproc;
END;
The package will not compile because you cannot declare a cursor in the
specification. (*)
TAXPROC is public and TAXFUNC is private.
Correct
(1/1) Points
17. Your schema contains a package 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 (*)
Correct
(1/1) Points
18. SCOTT's schema contains a package EMP_PKG which contains a public
procedure EMP_SAL which accepts a NUMBER parameter. Which of the following
will invoke the procedure successfully?
scott.emp_pkg.emp_sal(101): (*)
emp_pkg.emp_sal(101);
emp_sal(101);
All of these.
None of these.
Correct
(1/1) Points
19. 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?
forward declaration
package initialization block (*)
bodiless package
None of these.
Correct
(1/1) Points
20. 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;

global_consts.mile_to_km (*)
mile_to_km (global_consts)
mile_to_km.global_consts
global_consts (mile_to_km)
Correct

21. Examine the following package code:


CREATE OR REPLACE PACKAGE over_pack IS
PROCEDURE do_work1 (p1 IN VARCHAR2, p2 IN NUMBER);
PROCEDURE do_work2 (p1 IN VARCHAR2, p2 IN NUMBER);
PROCEDURE do_work1 (param1 IN CHAR, param2 IN NUMBER);
FUNCTION do_work2 (param1 IN VARCHAR2, param2 IN NUMBER) RETURN
DATE;
END over_pack;

Which of the following calls will be successful? (Choose three.)

(Choose all correct answers)


v_date := over_pack.do_work2('Smith',20); (*)
over_pack.do_work2('Smith',20); (*)
over_pack.do_work1(p1=>'Smith',p2=>20); (*)
over_pack.do_work1(20,'Smith');
over_pack.do_work1(param1=>'Smith');
Correct
(1/1) Points
22. A package initialization block is executed automatically every time a user
invokes any procedure or function in the package. True or False?
True
False (*)
Correct
(1/1) Points
23. Which of the following statements about a package initialization block is true?
It is a procedure in a package that must be invoked before the rest of the
package can be used.
It is an anonymous block in the package specification.
It cannot contain any SQL statements.
It is an anonymous block at the end of a package body. (*)
It is executed automatically every time any global variable in the package is
referenced.
Correct
(1/1) Points
24. Which one of the following is NOT a restriction on a package function called
from a SQL statement?
The function can return a BOOLEAN.
The function can include a ROLLBACK.
The function can be overloaded. (*)
The function can include a COMMIT.
Correct
(1/1) Points
25. If a subprogram is public (declared in the package specification), its detailed
code can be written anywhere in the package body without the need to use
forward declarations. True or False?
True (*)
False
Correct

26. A bodiless package contains what?

Functions only

Private variables only

Public variables 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?

1. FUNCTION get_emp (p1 DATE) RETURN VARCHAR2;


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;

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)

29. Package MULTIPACK declares the following global variable:


g_myvar NUMBER;

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: null (*)

Dick: 45, Hazel: 45

Dick: 0, Hazel: 0

Both queries will fail because the syntax of DBMS_OUTPUT.PUT_LINE is incorrect

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

Incorrect. Refer to Section 11 Lesson 2.

(0/1) Points

37. The DBMS_OUTPUT package is useful for which of the following activities? (Choose
two)

(Choose all correct answers)

Display results to the developer during testing for debugging purposes (*)

Interact with a user during execution of a function or procedure

Write operating system text files to the user's screen

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

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

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


UPDATE employees
SET salary = salary * 1.1;
When is this SQL statement parsed?
When the package specification 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
When the package body is created (*)
Correct
(1/1) Points
42. The DBMS_SQL package is easier to use than EXECUTE IMMEDIATE. True or
False?
True
False (*)
Correct
(1/1) Points
43. Which of the following SQL statements can be included in a PL/SQL block only
by using Dynamic SQL? (Choose two.)
(Choose all correct answers)
DELETE
SELECT ..... FOR UPDATE NOWAIT
GRANT (*)
ALTER (*)
SAVEPOINT
Correct
(1/1) Points
44. Dynamic SQL enables data-definition, data-control, or session-control
statements to be written and executed from PL/SQL.
True (*)
False
Correct
(1/1) Points
45. In the following example, where do you place the phrase DETERMINISTIC?
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
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;

Inserts the new department id in the department table


Uses the new department number in a cursor
Performs the SELECT statement to determine the department id of the new
department (*)
Correct
(1/1) Points
48. To create a list of the top 20 movies from a catalog of millions of titles, the
following statement grabs those rows using a collection. True or False?
...
TYPE nametab IS TABLE OF movies.title%TYPE INDEX BY BINARY_INTEGER;
Title_tab nametab;
...
SELECT title BULK COLLECT INTO title_tab FROM movies ORDER BY rental_count
DESC;
...

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;

FORALL does not require END LOOP. (*)


v_emptab is incorrectly typed.
The phrase should be FOR ALL.
Nothing is wrong; it will compile successfully.
Correct

You might also like