Mid Semester 2
Mid Semester 2
Mid Semester 2
Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 9
1. Examine the following package code:
CREATE OR REPLACE PACKAGE ol_pack IS
PROCEDURE subprog (p1 IN VARCHAR2, p2 IN NUMBER);
PROCEDURE subprog (param1 IN CHAR, param2 IN NUMBER);
FUNCTION subprog (param1 IN VARCHAR2, param2 IN NUMBER) RETURN DATE;
END ol_pack;
Which of the following calls will be successful? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)
ol_pack.subprog('Jane',30);
ol_pack.subprog(param1=>'Jane',param2=>30); (*)
v_number := ol_pack.subprog(p1=>'Jane');
v_date := ol_pack.subprog('Jane',30); (*)
Correct
Correct
Correct
Add a private function to the package body of TAXPACK, and invoke the functi
on from the user session.
Correct
5. Which of the following statements about packages is NOT true ? Mark for R
eview
(1) Points
All procedures and functions must be declared in the specification. (*)
Cursors can be declared in the specification.
The body contains the detailed code of the subprograms.
Variables can be declared in the body.
The specification must be created before the body.
Correct
6. Which one of the following can NOT be part of a Package ? Mark for Review
(1) Points
Procedures
Explicit cursors
Triggers (*)
Functions
Global variables
7. What is wrong with the following syntax for creating a package specificati
on?
CREATE OR REPLACE PACKAGE mypack IS
g_constant1 NUMBER(6) := 100;
FUNCTION func1 (p_param1 IN VARCHAR2);
FUNCTION func2;
END mypack;
Mark for Review
(1) Points
You cannot declare constants in the specification.
Correct
mypack.myproc(35);
(*)
myproc(40);
v_num := mypack.myproc(22);
Correct
9. A package contains both public and private subprograms. Which one of the f
ollowing statements is true? Mark for Review
(1) Points
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.
The whole package is loaded into memory when the first call is made to any s
ubprogram in the package. (*)
If three users invoke three different subprograms in the package, there will
be three copies of the code in memory.
Correct
10. In a package, public components are declared in the specification but pri
vate components are not. True or False? Mark for Review
(1) Points
True (*)
False
Correct
Page 1 of 5
Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 9
11. 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 o
f the following statements is NOT true?
Mark for Review
(1) Points
The procedure can be invoked by:
BEGIN
taxpack.taxproc;
END;
The packaage will not compile because you cannot declare a cursor in the spe
cification.
(*)
Correct
12. Package OLDPACK is in your schema. What will happen when the following st
atement is executed?
DROP PACKAGE oldpack;
Mark for Review
(1) Points
The body will be dropped but the specification will be retained.
The specification will be dropped but the body will be retained.
Both the specification and the body will be dropped. (*)
The statement will fail because you must drop the body before you can drop t
he specification.
Correct
13. 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 name = 'DEPTPACK'
AND type = 'PACKAGE'
ORDER BY line;
Correct
14. When a change is made to the detailed code of a public procedure in a pac
kage (but not to the procedure's name or parameters), both the specification and
the body must be recompiled. True or False? Mark for Review
(1) Points
True
False (*)
Correct
15. Your schema contains four packages, each having a specification and a bod
y. You have also been granted privileges to access three packages (and their bod
ies) in other users' schemas. What will be displayed by the following query?
SELECT COUNT(*) FROM ALL_OBJECTS
WHERE object_type LIKE 'PACK%'
AND owner <> USER;
Mark for Review
(1) Points
14
7
3
6 (*)
0
Correct
Correct
Correct
18. A SQL statement can pass through several stages. Which of the following i
s NOT one of these stages? Mark for Review
(1) Points
BIND
FETCH
PARSE
RETURN (*)
EXECUTE
Correct
Correct
20. The easiest way to include DDL statements in a PL/SQL block is to use the
DBMS_SQL package. True or False? Mark for Review
(1) Points
True
False (*)
Correct
Page 2 of 5
Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 9
21. Examine the following code:
CREATE OR REPLACE PROCEDURE myproc IS
CURSOR c_curs IS SELECT view_name FROM user_views;
BEGIN
FOR v_curs_rec IN c_curs LOOP
EXECUTE IMMEDIATE 'DROP VIEW ' || v_curs_rec.view_name;
END LOOP;
END;
What will happen when this procedure is invoked?
Mark for Review
(1) Points
All views in the user's schema will be dropped. (*)
The procedure will not compile successfully because the syntax of EXECUTE IM
MEDIATE is incorrect.
The procedure will raise an exception because Dynamic SQL can drop tables bu
t cannot drop views.
The procedure will raise an exception because one of the views is a complex
view.
22. The DBMS_OUTPUT.PUT procedure places text in a buffer but does not displa
y the contents of the buffer. True or False? Mark for Review
(1) Points
True (*)
False
Incorrect. Refer to Section 9.
Correct
24. 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 anonymous blocks display messages while the block is executing, whil
e procedures do not display anything until their execution has finished
Because DBMS_OUTPUT should be used only for testing and debugging PL/SQL cod
e (*)
Because DBMS_OUTPUT can raise a NO_DATA_FOUND exception if used inside a pac
kaged procedure
Correct
25. 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 read and write text files stored outside the database. (*)
It is used to find out how much free space is left on an operating system di
sk.
It is used to query CHAR and VARCHAR2 columns in tables.
Correct
Section 10
26. INSTEAD OF triggers are always row triggers, even if FOR EACH ROW is omit
ted. True or False? Mark for Review
(1) Points
True (*)
False
Correct
27. With which kind of trigger can the :OLD and :NEW qualifiers be used? Mar
k for Review
(1) Points
DDL triggers
Database Event triggers
Statement triggers
Row triggers (*)
AFTER triggers
Correct
28. Which of the following can NOT be coded in the body of a DML trigger? (Ch
oose two.) Mark for Review
(1) Points
(Choose all correct answers)
IF DELETING THEN
IF SELECTING THEN (*)
IF INSERTING THEN
Correct
Correct
Correct
Page 3 of 5
Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 10
31. The following code will successfully create emp_trigg: True or False?
CREATE OR REPLACE TRIGGER emp_trigg
BEFORE DELETE OF salary ON employees
BEGIN
RAISE_APPLICATION_ERROR(-20202,'Deleting salary is not allowed');
END;
Mark for Review
(1) Points
True
False (*)
Correct
Correct
33. There are five employees in department 50. The following trigger is creat
ed:
CREATE TRIGGER upd_emp
AFTER UPDATE ON employees
BEGIN
INSERT INTO audit_table VALUES (USER, SYSDATE);
END;
A user now executes:
UPDATE employees SET salary = salary * 1.1
WHERE department_id = 50;
How many rows will be inserted into audit_table?
Mark for Review
(1) Points
One (*)
Two
Five
Six
None of the above
Correct
Correct
35. A business rule states that an employee's salary cannot be greater than 9
9,999.99 or less than 0. The best way to enforce this rule is by using: Mark fo
r Review
(1) Points
A datatype of NUMBER(7,2) for the SALARY column
A database trigger
A check constraint (*)
An application trigger
A view
Correct
36. You can code COMMIT and ROLLBACK statements in a trigger body. True or Fa
lse? Mark for Review
(1) Points
True
False (*)
Correct
37. A trigger can be a public subprogram within a PL/SQL package. True or Fal
se? Mark for Review
(1) Points
True
False (*)
Correct
38. Which of the following are good guidelines to follow when creating a data
base trigger? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)
Where possible, use a trigger to enforce a foreign key constraint.
Use triggers to override privilege checking and view other users' private ta
bles.
Do not use a trigger to replace or duplicate something which the Oracle Serv
er does automatically. (*)
Correct
pack1.packproc(25); (*)
SELECT func1(100) FROM dual;
trigg1;
IF pack1.packfunc(40) THEN ...
IF func1(75) THEN ... (*)
Correct
40. What type of database object would you create to write an auditing record
automatically every time a user connects to the database? Mark for Review
(1) Points
A procedure
A complex view
A trigger (*)
A function
A package
Correct
Page 4 of 5
Review your answers, feedback, and question scores below. An asterisk (*) indica
tes a correct answer.
Section 10
41. Examine this code:
CREATE TRIGGER de_trigg
-- Line A
BEGIN ...
Which of the following are NOT valid at Line A ? (Choose two.)
Mark for Review
(1) Points
(Choose all correct answers)
Correct
42. Which of the following statements could cause a DDL trigger to fire? Mar
k for Review
(1) Points
DROP TABLE employees;
ALTER TABLE departments ADD (budget NUMBER(8,2));
CREATE TABLE newemp AS SELECT * FROM employees;
TRUNCATE TABLE locations;
All of the above (*)
Correct
43. A trigger automatically inserts a row into a logging table every time a u
ser's session receives this error message:
ORA-00942: table or view does not exist
What kind of trigger is this? Mark for Review
(1) Points
A row trigger
A statement trigger
A database event trigger (*)
A DDL trigger
An AFTER trigger
Correct
Correct
46. The database administrator wants to write a log record every time an Orac
le Server error occurs in any user's session. The DBA creates the following trig
ger:
CREATE TRIGGER log_errs_trigg
-- Line A
BEGIN
INSERT INTO errlog_table VALUES (...);
END;
What should the DBA code at Line A ?
Mark for Review
(1) Points
AFTER ERROR ON DATABASE
AFTER SERVER ERROR ON DATABASE
AFTER SERVERERROR ON SCHEMA
AFTER SERVERERROR ON DATABASE (*)
AFTER ORACLE ERROR ON SCHEMA
Correct
47. What is the purpose of using the CALL statement in a trigger? Mark for R
eview
(1) Points
It allows an INSTEAD OF trigger to be a statement trigger.
It allows the trigger body code to be placed in a separate procedure. (*)
It prevents cascading triggers.
It allows the trigger body code to be placed in a separate procedure or func
tion.
It allows both DML events and DDL events to be handled using a single trigge
r.
Correct
48. MARY and JOE's schemas each contain an EMPLOYEES table. JOE creates the f
ollowing trigger:
CREATE TRIGGER upd_trigg
AFTER DELETE ON joe.employees
FOR EACH ROW
BEGIN
DELETE FROM mary.employees
WHERE employee_id = :OLD.employee_id;
END;
A third user TOM needs to delete rows from JOE's EMPLOYEES table. What object pr
ivileges will TOM and JOE need?
Mark for Review
(1) Points
TOM does not need any object privileges, but JOE needs DELETE on both TOM.EM
PLOYEES and MARY.EMPLOYEES
TOM needs DELETE on JOE.EMPLOYEES and JOE needs DELETE on MARY.EMPLOYEES (*)
JOE does not need any object privileges, but TOM needs DELETE on MARY.EMPLOY
EES
TOM needs DELETE on MARY.EMPLOYEES and JOE needs EXECUTE on TOM.UPD_TRIGG
Correct
49. You need to disable all triggers that are associated with DML statements
on the DEPARTMENTS table. Which of the following commands should you use? Mark
for Review
(1) Points
ALTER TABLE departments DISABLE ALL TRIGGERS; (*)
ALTER TRIGGER DISABLE ALL ON departments;
ALTER TABLE departments DISABLE TRIGGERS;
DISABLE ALL TRIGGERS ON departments;
ALTER TABLE departments DROP ALL TRIGGERS;
Correct
50. Which dictionary view shows the detailed code of a trigger body? Mark fo
r Review
(1) Points
USER_SOURCE
USER_TRIGGERS (*)
USER_OBJECTS
USER_DML_TRIGGERS
USER_SUBPROGRAMS
Correct
Page 5 of 5