Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Quiz 10

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7
At a glance
Powered by AI
Packages allow grouping of related objects like procedures, functions and variables. They also provide data hiding and encapsulation.

A package can contain procedures, functions, variables, constants, exceptions, cursors and other nested packages.

The specification declares the interface and the body contains the implementation. The specification is visible to the calling programs while the body is not.

1.

 Which one of the following can NOT be part of a Package ?


Mark for Review

(1) Points
Global variables
Explicit cursors
Triggers (*)
Procedures
Functions
Correct

2. 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?
Mark for Review

(1) Points
DESCRIBE del_emp
DESCRIBE show_emp
DESCRIBE emp_pack(del_emp, show_emp)
None of these.
DESCRIBE emp_pack.del_emp
DESCRIBE emp_pack.show_emp
DESCRIBE emp_pack (*)
Correct

3. What is wrong with the following syntax for creating a package


specification?
CREATE OR REPLACE mypack IS
    g_constant1 NUMBER(6) := 100;
    PROCEDURE proc1 (p_param1 IN VARCHAR2);
    PROCEDURE proc2;
END mypack;

Mark for Review

(1) Points
The keyword PACKAGE is missing. (*)
Nothing is wrong, this code contains no errors.
The first line should be:
CREATE OR REPLACE PACKAGE SPECIFICATION mypack IS
You cannot declare constants in the specification.
A package must contain at least one function.
Correct

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

Mark for Review

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

5. Which of the following are good reasons for creating and using Packages?

A. Related procedures, functions, and variables can be grouped together


as a single unit
B. We can recompile the package body without having to recompile the
specification
C. We can create packages without needing any system privileges
D. The detailed package body code is invisible to the calling environment.

Mark for Review

(1) Points
A and C
A, B, C, and D
A and B
A, B, and C
A, B, and D (*)
Correct
6. The following package is valid. True or False?
CREATE OR REPLACE PACKAGE exceptions_pkg IS
 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;

Mark for Review

(1) Points
True (*)
False
Correct

7. A package initialization block is executed automatically every time a user


invokes any procedure or function in the package. True or False?
Mark for Review

(1) Points
True
False (*)
Correct

8. The following example package specification is valid to create a data type


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

9. 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;

Mark for Review

(1) Points
mile_to_km (global_consts)
global_consts.mile_to_km (*)
global_consts (mile_to_km)
mile_to_km.global_consts
Correct

10. The following example shows a valid record data type and variable. True
or False?
TYPE DeptRecTyp
  IS RECORD (deptid NUMBER(4) NOT NULL := 99,
  dname departments.department_name%TYPE,
  loc departments.location_id%TYPE,
  region regions.region_id%TYPE );
dept_rec DeptRecTyp;

Mark for Review

(1) Points
True (*)
False
Correct
Previous
11. Which of the following will display the detailed code of the subprograms
in package DEPTPACK in your schema ?
Mark for Review

(1) Points
SELECT text FROM USER_SOURCE
WHERE object_name = 'DEPTPACK'
AND object_type = 'PACKAGE BODY'
ORDER BY line;
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'PACKAGE BODY'
ORDER BY line; (*)
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'PACKAGE'
ORDER BY line;
SELECT text FROM USER_SOURCE
WHERE name = 'DEPTPACK'
AND type = 'BODY'
ORDER BY line;
Correct

12. 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;

Mark for Review

(1) Points
Point A
Point D
Point B or Point C, they will both work
Point B (*)
Point C
Correct

13. What will be displayed when a user executes the following statement?


SELECT object_name FROM user_objects
    WHERE object_type LIKE 'PACK%';

Mark for Review

(1) Points
The parameters which must be used when invoking all packaged
subprograms in the user's schema
The names of all package specifications in the user's schema
The detailed code of all packages in the user's schema
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 (*)
Correct

14. When one component of a package is called, all the package's


components are loaded into memory. True or False?
Mark for Review

(1) Points
True (*)
False
Correct

15. Package OLDPACK is in your schema. What will happen when the


following statement is executed?
DROP PACKAGE oldpack;

Mark for Review

(1) Points
The statement will fail because you must drop the body before you can drop
the specification.
The specification will be dropped but the body will be retained.
The body will be dropped but the specification will be retained.
Both the specification and the body will be dropped. (*)
Correct
Previous

You might also like