Sunteți pe pagina 1din 18

1.

We want to Mark for Review


remove
both the (1) Points
specification
and the
body of
package
CO_PACK
from the
database.
Which of
the
following
commands
will do this?

DROP PACKAGE SPECIFICATION co_pack;


DROP BOTH co_pack;
None of these.
DROP PACKAGE co_pack; (*)
DROP PACKAGE BODY co_pack;

Correct

2. Which one of the following queries would you use to see the detailed code of a Mark for Review
package called EMP_PKG?
(1) Points

SELECT source FROM user_packages WHERE name = 'EMP_PKG' AND


type = 'PACKAGE BODY' ORDER BY line;
SELECT text FROM user_source 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' ORDER BY line;

Correct

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

True (*)
False

Correct

4. A local variable defined inside a package procedure is visible to the calling Mark for Review
environment. True or False?
(1) Points
True
False (*)

Correct

5. We want to remove the specification (but not the body) of package BIGPACK Mark for Review
from the database. Which of the following commands will do this?
(1) Points

None of these. (*)


DROP PACKAGE bigpack SPECIFICATION;
DROP PACKAGE SPECIFICATION bigpack;
DROP PACKAGE HEADER bigpack;
DROP PACKAGE bigpack;

Correct
Section 10
(Answer all questions in this section)

6. Examine the following package specification: Mark for Review

CREATE OR REPLACE PACKAGE taxpack IS (1) Points


CURSOR empcurs IS SELECT * FROM employees;
PROCEDURE taxproc;
END mypack;

The package body of TAXPACK also includes a function called TAXFUNC. Which one of
the following statements is NOT true?

TAXPROC is public and TAXFUNC is private.


TAXPROC can invoke TAXFUNC if TAXPROC is coded before TAXFUNC.
The package will not compile because you cannot declare a cursor in the
specification.

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

BEGIN
taxpack.taxproc;
END;

Correct

7. We need to declare a package variable named MYVAR, which can be referenced by Mark for Review
any subprogram in the package but can NOT be referenced from outside the package.
In the following code, where should MYVAR be declared? (1) Points
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 D
Point C
Point B or Point C, they will both work
Point B (*)
Point A

Correct

8. Examine the following package specification: Mark for Review

CREATE OR REPLACE PACKAGE mypack IS (1) Points


percent_tax NUMBER := 20;
PROCEDURE proc1;
END mypack;

The package body of mypack also includes a function called func1. Which of the
following statements are true? (Choose three.)

(Choose all correct answers)

proc1 is a public procedure and func1 is a private function.

(*)
The package will not compile because you cannot declare variables in the
specification, only procedures and functions. .
The procedure can be invoked by:

BEGIN
mypack.proc1;
END;

(*)
The variable can be modified by:
BEGIN
mypack.percent_tax := 10;
END;

(*)
The function can be invoked from outside the package.

Incorrect. Refer to Section 10 Lesson 2.

9. SCOTT's schema contains a package EMP_PKG which contains a public procedure Mark for Review
EMP_SAL which accepts a NUMBER parameter. Which of the following will invoke the
procedure successfully? (0) Points

emp_sal(101);
emp_pkg.emp_sal(101);
All of these.
None of these.
scott.emp_pkg.emp_sal(101): (*)

Correct

10. What will be displayed when a user executes the following statement? Mark for Review

SELECT object_name FROM user_objects (0) Points


WHERE object_type LIKE 'PACK%';

The names of all packages which can be invoked by the user


The names of all package specifications and package bodies in the user's schema
(*)
The detailed code of all packages in the user's schema
The names of all package specifications in the user's schema
The parameters which must be used when invoking all packaged subprograms in
the user's schema

Correct
Section 10
(Answer all questions in this section)

11. A package initialization block is executed automatically every time a user invokes any Mark for Review
procedure or function in the package. True or False?
(1) Points

True
False (*)

Correct
12. An package initialization block automatically executes once and is used to initialize Mark for Review
public and private package variables. True or False?
(1) Points

True (*)
False

Incorrect. Refer to Section 10 Lesson 3.

13. The following call to the function tax in the taxes_pkg package is invalid for what Mark for Review
reason?
(1) Points
SELECT taxes_pkg.tax(salary), salary, last_name
FROM employees;

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. (*)
The call to the function should be taxes_pkg (tax.salary).

Incorrect. Refer to Section 10 Lesson 3.

14. The following package is valid. True or False? Mark for Review

CREATE OR REPLACE PACKAGE exceptions_pkg IS (1) Points


e_cons_violation EXCEPTION;
PRAGMA EXCEPTION_INIT (e_cons_violation, -2292);
e_value_too_large EXCEPTION;
PRAGMA EXCEPTION_INIT (e_value_too_large, -1438);
END exceptions_pkg;

True (*)
False

Correct

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

True (*)
False

Correct
Section 10
(Answer all questions in this section)
16. INDEX BY is missing from the emp_tab TYPE declaration. What is the most efficient Mark for Review
declaration?
(1) Points
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;

INDEX BY INTEGER
INDEX ALL
INDEX BY BINARY_INTEGER (*)
INDEX BY BINARY

Correct

17. The following example package specification is valid to create a data type ed_type that Mark for Review
can be used in other subprograms. True or False?
(1) Points
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;

True (*)
False

Correct

18. Package TAXPACK declares a global variable G_TAXRATE NUMBER(2,2). The value of Mark for Review
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 (1) Points
TAXPACK. How would you do this?

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.
Declare the global variable as:
g_taxrate NUMBER(2,2) := SELECT tax_rate FROM taxtab;
Add a package initialization block to the package body of TAXPACK.

(*)

Correct
19. How would you invoke the constant km_to_mile from the global_consts bodiless Mark for Review
package at VARIABLE A?
(1) Points
SELECT trail_name, distance_in_km * VARIABLE A
FROM trails
WHERE park_name = 'YOSEMITE';

global_consts (km_to_mile)
km_to_mile (global_consts)
km_to_mile.global_consts
global_consts.km_to_mile (*)

Correct

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

(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;

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

(*)
CREATE OR REPLACE PACKAGE BODY forward_pack IS
PROCEDURE proc2;
PROCEDURE proc1 IS
BEGIN
proc2;
END;
PROCEDURE proc2 IS
BEGIN
proc1;
END;
END forward_pack;

Correct
21. The following Mark for Review
package specification
has been created: (1) Points

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)

mypack.myproc(35);

(*)
IF NOT mypack.myfunc(SYSDATE) THEN
DBMS_OUTPUT.PUT_LINE('Message');
END IF;
(*)
v_num := mypack.myproc(22);
mypack.myfunc('22-Jan-2007');
myproc(40);

Correct

22. Package EMP_PACK contains two procedures, DEL_EMP and Mark for Review
SHOW_EMP. You want to write an anonymous block which invokes
these procedures but you have forgotten which parameters they (1) Points
use. Which of the following will give you this information?

DESCRIBE emp_pack.del_emp
DESCRIBE emp_pack.show_emp
DESCRIBE emp_pack(del_emp, show_emp)
DESCRIBE emp_pack

(*)
None of these.
DESCRIBE del_emp
DESCRIBE show_emp

Correct

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

Nothing is wrong, this code contains no errors.


The first line should be:
CREATE OR REPLACE PACKAGE SPECIFICATION mypack IS
The keyword PACKAGE is missing.

(*)
You cannot declare constants in the specification.
A package must contain at least one function.

Correct

24. Which of the following statements about packages is NOT true ? Mark for Review
(1) Points

Cursors can be declared in the specification.


All procedures and functions must be declared in the
specification. (*)
The body contains the detailed code of the subprograms.
The specification must be created before the body.
Variables can be declared in the body.

Correct

25. Which one of the following can NOT be part of a Package ? Mark for Review
(1) Points

Explicit cursors
Procedures
Functions
Global variables
Triggers (*)

Correct
Section 10
(Answer all questions in this section)

26. Package Specification DEPT_PACK was created by the following code: Mark for Review

CREATE OR REPLACE PACKAGE dept_pack IS (1) Points


PROCEDURE ins_dept(p_deptno IN NUMBER);
FUNCTION get_dept(p_deptno IN NUMBER) RETURN VARCHAR2;
END dept_pack;

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

(Choose all correct answers)

CREATE PROCEDURE dept_proc IS


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

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

(*)

Correct

27. To be able to invoke a package subprogram from outside the package, it must be Mark for Review
declared in the package:
(1) Points

Body and the specification (*)


Specification
Body
None of these.

Correct

28. In which component of a package is the full definition of a public procedure written? Mark for Review
(1) Points

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

Correct

Section 11
(Answer all questions in this section)

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

True
False (*)

Correct
30. Why is it better to use DBMS_OUTPUT only in anonymous blocks, not inside stored Mark for Review
subprograms such as procedures?
(1) Points

Because DBMS_OUTPUT can raise a NO_DATA_FOUND exception if used inside a


packaged procedure
Because anonymous blocks display messages while the block is executing, while
procedures do not display anything until their execution has finished
Because DBMS_OUTPUT should be used only for testing and debugging PL/SQL
code (*)
Because DBMS_OUTPUT cannot be used inside procedures

Correct
Section 11
(Answer all questions in this section)

31. The UTL_MAIL package allows sending email from the Oracle database to remote Mark for Review
recipients.
(1) Points

True (*)
False

Correct

32. DBMS_OUTPUT.PUT_LINE can be invoked from inside a private packaged function. Mark for Review
True or False?
(1) Points

True (*)
False

Correct

33. What will be displayed when the following code is executed? Mark for Review

BEGIN (1) Points


DBMS_OUTPUT.PUT('I do like');
DBMS_OUTPUT.PUT_LINE('to be');
DBMS_OUTPUT.PUT('beside the seaside');
END;

I do like to be beside the seaside


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

(*)
I do like
to be
beside the seaside

Correct

34. The DBMS_OUTPUT gives programmers an easy-to-use interface to see, for instance, Mark for Review
the current value of a loop counter, or whether or not a program reaches a particular
branch of an IF statement. (True or False?) (1) Points

True (*)
False

Correct

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

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

An error will occur at line 4. (*)


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

Correct
Section 11
(Answer all questions in this section)

36. In the following example, which statement best fits in Line 1? (Choose 1) Mark for Review

DECLARE (1) Points


v_more_rows_exist BOOLEAN := TRUE;
BEGIN
-- Line 1
LOOP
v_more_rows_exist := curs_pkg.fetch_n_rows(3);
DBMS_OUTPUT.PUT_LINE('-------');
EXIT WHEN NOT v_more_rows_exist;
END LOOP;
curs_pkg.close_curs;
END;
curs_pkg.close_curs;
curs_pkg.open_curs; (*)
curs_pkg.emp_curs%ISOPEN;
EXIT WHEN curs_pkg.emp_curs%NOTFOUND;

Correct

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

True (*)
False

Correct

38. Package MULTIPACK declares the following global variable: Mark for Review
g_myvar NUMBER;
(1) Points
User DICK executes the following:
multipack.g_myvar := 45;

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

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

What values will Dick and Hazel see?

Dick: 45, Hazel: 0


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

Correct

Section 12
(Answer all questions in this section)

39. What are benefits of using the NOCOPY hint? (Choose two) Mark for Review
(1) Points
(Choose all correct answers)

Efficient since it uses less memory (*)


Safer because it uses passing by value
Faster because a single copy of the data is used (*)
Uses a larger block of server memory for faster access

Correct

40. In the following example, where do you place the phrase DETERMINISTIC? Mark for Review

CREATE OR REPLACE FUNCTION total_sal (1) Points


(p_dept_id IN -- Position A
employees.department_id%TYPE)
RETURN NUMBER -- Position B
IS v_total_sal NUMBER;
BEGIN
SELECT SUM(salary) INTO v_total_sal
FROM employees WHERE department_id = p_dept_in;
RETURN v_total_sal -- Position C;
END total_sal;

Position A
Position B (*)
Position C

Correct
Section 12
(Answer all questions in this section)

41. What is the correct syntax to use the RETURNING phrase at Position A? Mark for Review

DECLARE (1) Points


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

RETURNING FROM emp_info;


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

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

True (*)
False

Correct

43. The following example code will compile successfully. True or False? Mark for Review

CREATE OR REPLACE PROCEDURE dept_proc IS (1) Points


TYPE t_dept IS TABLE OF departments%ROWTYPE INDEX BY BINARY_INTEGER;
BEGIN
(p_small_arg IN NUMBER, p_big_arg OUT NOCOPY t_dept);
-- remaining code
END dept_proc;

True (*)
False

Incorrect. Refer to Section 12 Lesson 2.

44. The following procedure compiles successfully. True or False? Mark for Review

CREATE OR REPLACE PACKAGE emp_pkg IS (1) Points


TYPE t_emp IS TABLE OF employees%ROWTYPE
INDEX BY BINARY_INTEGER;
PROCEDURE emp_proc
(p_small_arg IN NUMBER, p_big_arg NOCOPY OUT t_emp);
...
END emp_pkg;

True
False (*)

Incorrect. Refer to Section 12 Lesson 2.

45. A public packaged procedure contains the following SQL statement: Mark for Review
UPDATE employees
SET salary = salary * 1.1; (1) Points
When is this SQL statement parsed?

When the package body is created (*)


When the package header is loaded into memory
When the package is loaded into memory
When the package specification is created
Only the first time the procedure is executed

Correct
Section 12
(Answer all questions in this section)

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

True
False (*)

Correct

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

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

(Choose all correct answers)

EXECUTE v_first_string || p_col_name || v_second_string;


EXECUTE IMMEDIATE 'v_first_string' || p_col_name || 'v_second_string';
v_first_string := v_first_string || p_col_name;
EXECUTE IMMEDIATE v_first_string || v_second_string;

(*)
EXECUTE IMMEDIATE v_first_string || p_col_name || v_second_string;

(*)
v_first_string || p_col_name || v_second_string;

Incorrect. Refer to Section 12 Lesson 1.

48. For which of the following is it necessary to use Dynamic SQL? (Choose three.) Mark for Review
(1) Points

(Choose all correct answers)


GRANT (*)
ALTER (*)
UPDATE
DROP (*)
SAVEPOINT

Correct

49. What will happen when the following procedure is invoked? Mark for Review

CREATE OR REPLACE PROCEDURE do_some_work IS (1) Points


CURSOR c_curs IS SELECT object_name FROM user_objects
WHERE object_type = 'FUNCTION';
BEGIN
FOR v_curs_rec IN c_curs LOOP
EXECUTE IMMEDIATE 'ALTER FUNCTION ' || v_curs_rec.object_name || '
COMPILE';
EXIT WHEN c_curs%ROWCOUNT > 2;
END LOOP;
END;

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


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

Correct

50. Name two reasons for using Dynamic SQL. Mark for Review
(1) Points

(Choose all correct answers)

Enables data-definition statements to be written and executed from PL/SQL (*)


Enables system control statements to be written and executed from PL/SQL
Creates a SQL statement with varying column data, or different conditions (*)
Avoids errrors at compile time of DML statements

Correct

S-ar putea să vă placă și