PLSQL Q&a
PLSQL Q&a
Which of the following keywords are required in any PL/SQL block? (Choose all that
apply.)
A. DECLARE
B. BEGIN
C. EXCEPTION
D. END
2.
What is wrong with the following code? (Choose all that apply.)
DECLARE
v_answer VARCHAR2(30);
BEGIN
v_answer + v_result := v_one / v_two;
END;
A.
B.
C.
D.
3.
4.
What will happen when the following code is executed? (Choose all that apply.)
DECLARE
CURSOR cur_cruises IS
SELECT CRUISE
FROM CRUISES;
rec_cruises cur_cruises%ROWTYPE;
BEGIN
OPEN cur_cruises;
SELECT CRUISE
INTO rec_cruises
FROM CRUISES;
CLOSE cur_cruises;
EXCEPTION
WHEN OTHERS THEN
INSERT INTO ERRORS
(ERROR_ID, MESSAGE)
VALUES
(SEQ_ERROR_ID.NEXTVAL,'Something is wrong');
COMMIT;
END;
A. Nothing, the code will not parse correctly.
B. The TOO_MANY_ROWS exception will be raised, which is not handled, and
the PL/SQL code will terminate with an error message.
C. It depends on how many rows are in the database.
D. The message, Something is wrong, will definitely be inserted into the
ERRORS table.
5.
Which of the following is not a cursor attribute? (Choose all that apply.)
A. %ISOPEN
B. %ISNOTOPEN
C. %FOUND
D. %NOTFOUND
6.
VARCHAR2(30));
END;
A. The HOLIDAYS table will be created.
B. The TOO_MANY_ROWS exception will be raised, but since it's not handled,
nothing will happen.
C. A parsing error will occur.
D. The table will be created, but won't be declared since it isn't created in the
DECLARE section.
7.
Which of the following are valid names for program units? (Choose all that apply.)
A. PROCESS_ORDER
B. SETUP-THE-DATABASE
C. 100_SAMPLE_RECORDS
D. GET_ORDER_#
8.
You have created a PL/SQL block that declares variables using the %TYPE feature.
When you created the block, the column upon which you based the %TYPE
declaration had a datatype of NUMBER, but since you first created the block, it has
been altered to have a datatype of VARCHAR2. Which of the following system-defined
exceptions is most likely to occur in your block if you were you to execute the block
now without modification?
A. NO_DATA_FOUND
B. VALUE_ERROR
C. PROGRAM_ERROR
D. VALUE_CONFLICT
10. How many passes through the loop will occur? (Choose all that apply.)
DECLARE
FOR rec_ships IN (SELECT SHIP_ID FROM SHIPS)
LOOP
IF (rec_ships.SHIP_ID = 1)
THEN
EXIT;
END IF;
END LOOP;
END;
/
A. Once for each record in the SHIPS table.
B. Only one. The EXIT will execute on the first record returned.
C. None, this code won't parse since you can't have an EXIT statement in a
Cursor FOR LOOP.
D. None of the above.
Answers
1.
Explanation Only BEGIN and END are required. DECLARE is only used in anonymous
blocks that require elements to be declared. EXCEPTION is only used when exception
handlers are specified.
2.
A, B. A: Three variables need to be declared. B: You cannot use two variables on the left side
of an assignment statement.
Explanation Any and all variables and constants that are used in a PL/SQL block must be
declared. In this example, only the variable v_answer is declared. The others, v_result, v_one,
and v_two, all need to be declared. The left side of the assignment statement is the target of
the assignment, and therefore must be one single variable. The slash is the symbol for
division and is completely acceptable.
3.
4.
5.
B. %ISNOTOPEN
Explanation The four attributes are %ISOPEN, %FOUND, %NOTFOUND, and
%ROWCOUNT. There is no such thing as %ISNOTOPEN.
6.
7.
8.
C. Complete.
Explanation A would have been correct had the IF statement evaluated to TRUE. Even
though the user-defined exception is defined in the outer block, it is global to the inner block,
and the inner block's exception handler will recognize the RAISE statement. If the RAISE
statement would be executed, then the inner block's exception handler would have handled
the exception, and the outer block's exception handler would never have been relevant, so B
is not true. And since the user-defined exceptions are handled in both blocks, then D is not
true. But C is true because the IF statement considers booked_cabins as the locally declared
constant with a value of 199 and total_cabins as the globally declared variable with a value of
250. The comparison in the IF statement evaluates to FALSE, and the inner block completes,
followed by the statement that prints the word Complete.
9.
B. VALUE_ERROR
Explanation A occurs when you write an implicit cursor that attempts to SELECT INTO a
variable, but the SELECT returns no rows. C generally indicates some sort of major system
bug. D is not a system-defined exception; I just made that up, but get used to that. Oracle
loves to make up bogus names like this on the real OCP. The answer is B because
VALUE_ERROR occurs when datatype conflicts exist, and if you've written code that was
expecting a NUMBER datatype that is now a VARCHAR2 datatype, then datatype conflicts
within your code are possible.
11. You want to create a procedure that will take a parameter named salary_amount
whose value will be defined by the calling block. Assuming any database object
references below are accurate, which of the following parameter declarations are
acceptable? (Choose all that apply.)
A. salary_amount OUT EMPLOYEES.BONUS%TYPE
B. salary_amount IN OUT NUMBER(2)
C. salary_amount OUT VARCHAR2(30)
D. salary_amount EMPLOYEES.SALARY%ROWTYPE
E. None of the above
12. You are working with a procedure that is declared with the following header:
PROCEDURE PROC_HIRE_EMPLOYEE
(
p_employee_id NUMBER
, p_hire_date
DATE
DEFAULT LAST_DAY(SYSDATE)
, p_lastname
VARCHAR2
, p_firstname
VARCHAR2
, p_results
OUT BOOLEAN)
IS
Assuming that any of the following variables are properly declared, which of the
following is an acceptable call to this procedure? (Choose all that apply.)
A. PROC_HIRE_EMPLOYEE(p_lastname Jones, p_firstname Joe);
B. PROC_HIRE_EMPLOYEE(Joe,Jones, TRUE);
C. PROC_HIRE_EMPLOYEE(p_firstname Joe, p_lastname Jones, v_answer);
D. PROC_HIRE_EMPLOYEE(101, 03-JAN-2003, Jones, Joe, v_result);
13. A procedure called PROC_SHIPPING, with no declared parameters, is already stored
in the database, but has a status of INVALID. What will happen when you execute the
following statement in SQL*Plus? (Note: NULL is a valid PL/SQL statement.)
CREATE PROCEDURE PROC_CHECK_SHIPPING
IS
BEGIN
NULL;
END PROC_CHECK_SHIPPING;
A. The procedure will overwrite the existing stored procedure, and the new status
will be VALID.
B. The attempt to create the procedure will fail due to a syntax error: The
procedure name cannot be repeated after the END statement.
C. The attempt to create the procedure will fail due to an error: You cannot create
a procedure when another already exists with the same name.
D. The procedure will overwrite the existing stored procedure, but the status will
still be INVALID.
14. You've created a stored procedure called ADD_EMPLOYEES that includes an INSERT
statement for a table called EMPLOYEES. After you successfully store the procedure,
you ALTER the EMPLOYEES table by dropping a column from the table. However, this
new column isn't referenced in your procedure. What must you now do to guarantee
that the procedure has a status of VALID? (Choose all that apply.)
A. ALTER PROCEDURE ADD_EMPLOYEES COMPILE;
IN DATE
DEFAULT (SYSDATE+2)
, p_lastname
IN VARCHAR2
, p_result
OUT BOOLEAN)
IS
BEGIN
IF (p_result IS NULL)
THEN
p_lastname := 'Smith';
END IF;
END;
Why will this procedure be given a status of INVALID? (Choose all that apply.)
A. The IF statement cannot refer to p_result yet because its parameter declaration
has no DEFAULT value.
B. The assignment of Smith to the p_lastname variable is not an option because
p_lastname is an IN parameter.
C. The p_employee_id parameter cannot use a SEQUENCE in its DEFAULT value
expression.
D. The p_hire_date parameter cannot be assigned a default value of
SYSDATE+2.
18. You have created a procedure and stored it in the database under your own schema.
Assuming you were to grant the required privileges, which of the following could
invoke your procedure? (Choose all that apply.)
A. Another stored procedure in your own schema
B. Another stored procedure in a different schema, but in the same database
C. A procedure stored in an Oracle Form, located on a client machine on your
NUMBER,
VARCHAR2)
IS
BEGIN
INSERT INTO ORDERS VALUES (ORDER_ID, SALES_REP);
END;
Assuming that the variable v_lastname has been properly declared, which of the
following calls to this procedure will parse within a PL/SQL block and execute
correctly without producing an error?
A. PROCESS_ORDER(101, Jones);
B. PROCESS_ORDER(101, v_lastname);
C. PROCESS_ORDER(101, SYSDATE);
D. PROCESS_ORDER(101, Jones);
Answers
13. C. The attempt to create the procedure will fail due to an error: You cannot create a procedure
when another already exists with the same name.
Explanation If the statement used the OR REPLACE option, it would have worked. But it
certainly may repeat the name of the procedure after the END statement. In fact, that's
considered good design.
14. A, D. A: ALTER PROCEDURE ADD_EMPLOYEES COMPILE; D: Nothing
Explanation Regardless of what change was made to the table EMPLOYEES, and
regardless of what specific action the procedure takes on that table, the fact is that if the table
is used in any SQL statement from within the procedure, and if any ALTER is issued on the
table, then the procedure should be recompiled. However, in reality, Oracle will automatically
attempt to recompile the procedure on its next invocation, and since the procedure doesn't
even reference the column, then the procedure will recompile fine at that time. The proper
syntax for performing the recompilation is A, with the COMPILE keyword. There is no
RECOMPILE keyword.
15. B. DROP PROCEDURE PROC_OBSOLETE;
Explanation No special keywords are required other than these. DELETE applies to tables
whose records you wish to remove, but DROP is always used to eliminate a database object
altogether.
16. B, C, D. B: USER_SOURCE
C: ALL_SOURCE
D: DBA_SOURCE
Explanation Any attempt of CREATE PROCEDURE will move source code into this set of
data dictionary views, regardless of whether or not the attempt was successful.
17. B, C. B: The assignment of Smith to the p_lastname variable is not an option because
p_lastname is an IN parameter. C: The p_employee_id parameter cannot use a SEQUENCE
in its DEFAULT value expression.
Explanation No IN parameters can be assigned values, and SEQUENCE generators are not
allowed in DEFAULT value declarations for parameters. What A says is true, but not for the
reason given; p_result should not be referenced because it is an OUT parameter, not an IN
parameter, and it hasn't been assigned a value yet. As an OUT parameter, it cannot be
assigned a DEFAULT value, but once the executable statements of the procedure begin, it
can be assigned a value with a standard PL/SQL assignment statement. After that, it can be
referenced in an IF statement. And D is allowable.
18. A, B, C, D. A: Another stored procedure in your own schema. B: Another stored procedure in a
different schema, but in the same database. C: A procedure stored in an Oracle Form, located
on a client machine on your network and logged in to a different schema in your database. D:
An anonymous PL/SQL block, saved in a text file, and executed in a SQL*Plus session that's
logged in as your own schema
Explanation A and D are true without any additional granting of privileges. B and C are true
provided that you grant privileges to the appropriate schema first. (Note: the topic of granting
privileges was introduced in this chapter, and will be explored in depth in Chapter 9.)
19. A, B, C, D.
A: EXEC PROC_UPDATE_STATUS;
B: EXECUTE PROC_UPDATE_STATUS();
C: BEGIN
PROC_UPDATE_STATUS;
END;
/
D: EXEC PROC_UPDATE_STATUS();
Explanation C is a standard call from an anonymous PL/SQL block. A, B, and D are all
acceptable SQL calls. When the procedure has no parameters, parentheses are not normally
used, but are accepted.
20. A, B, C.
A: PROCESS_ORDER('101', 'Jones');
B: PROCESS_ORDER('101', v_lastname);
C: PROCESS_ORDER(101, SYSDATE);
Explanation Thanks to Oracle's tendency to perform automatic datatype conversions, the
character string 101 will be converted to a numeric value in A and B. And although it's a little
silly for C to pass in the current system date as the value for the SALES_REP parameter,
nevertheless it will work. But D will not work because Jones is not enclosed in single quotes.
10
21. You have created a function called GET_TOTAL that takes no parameters. Assuming
that any other variables are properly declared, which of the following PL/SQL
statements includes a successful call to this function?
A. GET_TOTAL;
B. v_total := GET_TOTAL();
C. IF (GET_TOTAL = 101)
D. v_total := GET_TOTAL;
22. Consider the following code sample:
CREATE OR REPLACE FUNCTION GET_TOTAL
(cruise_id IN OUT NUMBER)
RETURN NUMBER
AS
total NUMBER(10);
BEGIN
SELECT COUNT(*)
INTO total
FROM CRUISES
WHERE CRUISE_ID = cruise_id;
END;
/
What will happen when you submit this to the SQL*Plus client interface? (Choose all
that apply.)
A. You will receive a parsing error because of the IN OUT parameter type, which is
unacceptable in functions.
B. You will receive a parsing error because there is no RETURN statement at the
end.
C. You will receive a parsing error because the parameter cruise_id cannot have
the same name as the column CRUISE_ID in the CRUISES table.
D. You will receive the Function created message.
23. You have created a function called CUSTOMER_BALANCE, as follows:
CREATE OR REPLACE FUNCTION CUSTOMER_BALANCE
(p_customer_id NUMBER)
RETURN NUMBER
IS
order_amount NUMBER(10,2);
BEGIN
SELECT SUM(ORDER_AMOUNT)
INTO order_amount
FROM ORDERS
WHERE CUSTOMER_ID = p_customer_id;
RETURN order_amount;
11
END;
/
You store the function in the database, it compiles successfully, and you test its
execution to demonstrate that it works as expected. Two weeks later, you issue the
following command to the database:
ALTER TABLE ORDERS ADD ORDER_STATUS VARCHAR2(1);
Once this has been done, which of the following statements will now produce an error
message?
A. ALTER FUNCTION CUSTOMER_BALANCE();
B. SELECT CUSTOMER_BALANCE FROM DUAL;
C. ALTER FUNCTION CUSTOMER_BALANCE COMPILE;
D. ALTER FUNCTION CUSTOMER BALANCE RECOMPILE;
24. You have stored a function in the database with the following header:
FUNCTION CALCULATE_DISCOUNT
RETURN BOOLEAN
IS
Assuming it has been successfully compiled and has a status of VALID, which of the
following statements is true? (Choose all that apply.)
A. It can be called from a SQL statement.
B. It can be called from a PL/SQL expression.
C. You can execute it with the SQL*Plus EXEC command.
D. It takes no parameters.
25. You have stored a function in the database with the following header:
FUNCTION GET_BOOKINGS(guest_id IN NUMBER DEFAULT 0)
RETURN NUMBER
AS
Assuming that any referenced variables are properly declared, which of the following
calls to this function will produce an error message? (Choose all that apply.)
A. SELECT GET_BOOKINGS(guest_id => 101) FROM DUAL;
B. SELECT GET_BOOKINGS(p_guest_id => 101) FROM DUAL;
C. v_answer := GET_BOOKINGS(101);
D. v_answer := GET_BOOKINGS;
26. You are creating a new function with the following header and declaration section:
FUNCTION EMPLOYEE_HIRE_DATE
(p_employee_id IN NUMBER)
RETURN DATE
IS
v_date DATE;
BEGIN
Which of the following RETURN statements will be accepted by the compiler for this
function? (Choose all that apply.)
A. RETURN SYSDATE;
12
B. From a procedure stored in the same Oracle Form in which the function is
stored
C. From a procedure in a different Oracle Form in which the function is stored
D. From an anonymous block in a text file that you execute from within the
SQL*Plus interface
Answers
14
A, B, C. A: RETURN SYSDATE;
26. B: RETURN No date was found;
C: RETURN v_date;
Explanation D is an incomplete statement. Note that upon execution, B will fail, but it will
compile correctly since the parser recognizes that a string literal could, theoretically, contain a
valid date, such as 01-JAN-2003. Even though the string literal clearly does not contain a
valid date in this example, the parser cannot recognize this fact; it is not until execution that
the string literal is actually inspected for automatic datatype conversion.
27. B. The function is stored and compiled but not yet executed.
Explanation There are no syntax errors with this function. The command is to CREATE OR
REPLACE the function but not to execute it.
28. B, D. B: It is not a function. D: The parameter represented by the value 101 is an IN
parameter.
Explanation Gotcha! Trick question! Or maybe we didn't get you this program unit must be
a procedure. Functions, regardless of what prefix they are given, cannot be invoked as a
single executable statement. So this must be a procedure. A is not necessarily truethis
procedure could have more parameters defined for it, provided those parameters have default
values, in which case the additional parameters just aren't required in this particular call to the
program unit. C cannot be true because only functions really RETURN a value. Procedures
can be compiled with a RETURN statement, and they will execute, but the RETURN
statement in a procedure has no more effect than merely stopping execution of the procedure;
it won't actually return anything. D must be true because the value 101 is a literal, and literals
can only be provided for IN parameters. OUT and IN OUT parameters must have a
mechanism to send back the data, such as a variable.
A, B, C, D. A: v_answer := cabin_status guest_name;
29. B: v_answer := cabin_status(guest_name);
C: v_answer := SUBSTR(cabin_status,1,1) INSTR(guest_name,1);
D: v_answer := guest_name(cabin_status);
Explanation A is okay because both cabin_status and guest_discount return VARCHAR2,
and this is a simple string concatenation. B is okay because guest_discount has a default
value for its parameter and returns a VARCHAR2, which is being passed to cabin_status as
its parameter value. C is okay because the results of both functions are having standard SQL
string functions applied to them. D is troublesome, but will be accepted by the compiler since
the parser recognizes that the VARCHAR2 datatype returned by the function cabin_status
might successfully convert in an automatic datatype conversion to the NUMBER datatype
required by the guest_discount function.
30. B. From a procedure stored in the same Oracle Form in which the function is stored
Explanation A is not true because no database program unit can access a program unit
stored in any client software. C is not true; no program unit in a Form can access any other
program unit stored in another Form. (However, note that if the function were stored in a
PL/SQL library that was shared between the Forms, then the answer would be yes.) D is false
for the same reason that A is false.
15
31. The database contains a package called marketing, but it does not contain any
program units called update_status. However, there is a procedure stored in the
database called update_status that isn't part of any package. Now, consider the
following code sample:
CREATE OR REPLACE PROCEDURE daily_batch
IS
BEGIN
marketing.update_status;
END;
/
What will happen when you attempt to execute this code?
A. PL/SQL will store the procedure, but it will produce an error message.
B. PL/SQL will store the procedure and will not produce an error message.
However, upon execution of daily_batch, an error message will display.
C. PL/SQL will store the procedure and will not produce an error message.
Furthermore, upon the attempt to execute the procedure daily_batch, PL/SQL
will find the program unit update_status in the package marketing, and when it
doesn't find update_status in marketing, it will execute the update_status
procedure stored in the database.
D. PL/SQL will store the procedure and will not produce an error message.
Furthermore, upon execution of daily_batch, there will be no error message.
32. What is the minimum required set of parts you must create to a build a valid package?
(Choose all that apply.)
A. A package specification
B. A package body
C. A package specification and a package body
D. A package construct
33. Assume the following package is stored in the database:
PACKAGE warehouse
AS
CURSOR cur_inventory IS
SELECT INVENTORY_ID, INVENTORY, QUANTITY
FROM
INVENTORY;
rec_inventory cur_inventory%ROWTYPE;
END warehouse;
Now consider the following anonymous PL/SQL block #1:
BEGIN
OPEN warehouse.cur_inventory;
END;
Finally, consider the anonymous PL/SQL block #2:
BEGIN
FETCH warehouse.cur_inventory INTO
16
warehouse.rec_inventory;
END;
You execute the anonymous PL/SQL block #1. Assuming you stay logged in to the
same user session, what is the result after you execute PL/SQL block #2? (Choose all
that apply.)
A. ORA-01001: invalid cursor
B. ORA-06510: PL/SQL: unhandled exception
C. PL/SQL procedure successfully completed
D. ERROR at line 1
34. Consider the following code sample:
CREATE OR REPLACE PACKAGE SPECIFICATION acct
IS
PROCEDURE make_entry(debit IN BOOLEAN, credit IN BOOLEAN, amt
IN
NUMBER);
PROCEDURE remove_entry(entry_id NUMBER);
PROCEDURE balance_books;
END acct;
/
When you submit this code to the database, what will be the result?
A. The package specification will be stored in the data dictionary with a status of
INVALID. The package will not be successfully created.
B. The package specification will be successfully created but unable to be used
because of the BOOLEAN parameters in some of the procedures.
C. The package specification will be successfully created but unable to be used
because the package body has not yet been created.
D. The package specification will be successfully created, and other program units
that reference this package can now be successfully compiled.
35. Consider the following package specification:
PACKAGE budget_parameters
AS
PROCEDURE SET_RATIO(ratio_id NUMBER, ratio_value VARCHAR2);
FUNCTION GET_RATIO(ratio_id NUMBER)
RETURN VARCHAR2;
END budget_parameters;
You have already stored the complete package, including the previous specification
and the appropriate package body, in the database and successfully created the
package. You have logged off and logged back into the system. You then invoke the
packaged function budget_parameters.get_ratio. Which of the following statements is
now true? (Choose all that apply.)
A. The package specification is in the SGA but not the body.
B. The procedure set_ratio can now be executed, but it could not have been
executed before the call to function get_ratio.
C. The portion of the package body containing the procedure set_ratio is in the
SGA but not the rest of the package.
17
D. The call to the procedure set_ratio will now execute faster than it would have
were the procedure set_ratio stored as a stand-alone procedure.
36. Which of the following queries produces a listing of the package specification of mkt?
A. SELECT TEXT FROM USER_SOURCE WHERE NAME = mkt AND TYPE =
PACKAGE SPECIFICATION ORDER BY LINE;
B. SELECT TEXT FROM USER_SOURCE WHERE NAME = MKT AND TYPE =
PACKAGE SPECIFICATION ORDER BY LINE;
C. SELECT TEXT FROM USER_SOURCE WHERE NAME = MKT AND TYPE =
PACKAGE ORDER BY LINE;
D. SELECT TEXT FROM USER_SOURCE WHERE NAME = mkt AND TYPE =
PACKAGE ORDER BY LINE;
37. Consider the following code:
PACKAGE accounting AS
ex_overbooked EXCEPTION;
END accounting;
The exception accounting.ex_overbooked is a
A. Public local exception
B. Public global exception
C. Private local exception
D. Private global exception
38. Consider the following code:
BEGIN
OPEN rates.cur_ledger;
END;
/
Assuming that rates is a valid stored package and that this code block successfully
executes, which of the following statements is now true? (Choose all that apply.)
A. cur_ledger is a public local construct.
B. cur_ledger is opened, but closes automatically when the previous sample
anonymous block concludes execution.
C. The cursor is now open and available for FETCH statements in other program
units.
D. cur_ledger is a private global construct.
39. Consider the following code:
PACKAGE limits AS
upper_bound NUMBER(3) := 10;
PROCEDURE initialize;
END limits;
PACKAGE BODY limits AS
PROCEDURE initialize IS
BEGIN
upper_bound := 25;
END initialize;
18
END limits;
Assume the package specification and package body for limits is stored in the
database. Now consider the following code block:
BEGIN
DBMS_OUTPUT.PUT_LINE(limits.upper_bound);
END;
/
You have just logged into the database and issued a SET SERVEROUTPUT ON
command. The next action you perform is to execute this block. What is the result?
A. 10
B. 25
C. NULL
D. PLS-00201: identifier LIMITS.UPPER_BOUND must be declared
40. Assuming you have a package called front_office, which of the following statements
are valid? (Choose all that apply.)
A. DROP PACKAGE FRONT_OFFICE COMPILE
B. DROP PACKAGE SPECIFICATION FRONT_OFFICE
C. DROP PACKAGE BODY FRONT_OFFICE
D. DROP PACKAGE FRONT_OFFICE CASCADE
Answers
31. A. PL/SQL will store the procedure, but it will produce an error message.
Explanation The packaged construct marketing.update_status must exist in order for the
CREATE PROCEDURE daily_batch statement to execute successfully. As is always the
case, the daily_batch procedure will be stored in the data dictionary regardless of the status of
the daily_batch procedure. In this case, the daily_batch procedure will be given a status of
INVALID. The existance of any stand-alone update_status procedure is irrelevant.
32. A. A package specification
Explanation To create a complete package, it is possible to simply create a package
specification. As long as the specification doesn't declare any procedures or functions but
instead declares constructs, such as variables, constants, user-defined exceptions, cursors,
and the like, then a package body is not needed.
33. C. PL/SQL procedure successfully completed
Explanation The packaged cursor is a construct that is global to the user session. Provided
that the same user is logged on, then when PL/SQL block #2 executes, it recognizes that the
cursor is already open, even though it was opened as a result of the previous PL/SQL block
#1's execution.
34. A. The package specification will be stored in the data dictionary with a status of INVALID.
The package will not be successfully created.
Explanation The word SPECIFICATION is not acceptable in the header of the package and
will produce a compilation error. However, the error will be misleadingthe compiler will
assume that SPECIFICATION is the name of your package and will fail to recognize the
19
intended name of the package, which in this example is acct. Once the word SPECIFICATION
is removed from this code, the package specification will compile accurately and can be used
to write other program units that reference these packaged constructs. The other program
units will compile correctly, but they will not successfully execute until the package body for
acct is created.
35. D. The call to the procedure set_ratio will now execute faster than it would have were the
procedure set_ratio stored as a stand-alone procedure.
Explanation Any call to any packaged construct has the effect of loading all the packaged
constructs for that package into the SGA, thus causing all future calls to those constructs to
execute faster than they would have if the individual procedures and functions were stored on
their own as stand-alone program units.
36. C. SELECT TEXT FROM USER_SOURCE WHERE NAME=MKT AND TYPE=PACKAGE
ORDER BY LINE
Explanation All object names are stored in the data dictionary in uppercase letters, and
packages are indicated with a type of PACKAGE. There is no type of PACKAGE
SPECIFICATION.
37. B. Public global exception
Explanation Because the exception is declared in a package as a separate construct (as
opposed to being defined within the definition of a packaged procedure or packaged function),
it is inherently public. Furthermore, because it is defined within the package specification, it is
public. If it were declared in the package body, it would be private.
38. C. The cursor is now open and available for FETCH statements in other program units.
Explanation The cur_ledger construct is a public global construct and is a cursor. As such, it
can be opened in one block, fetched in another, and closed in still another block.
39. A. 10
Explanation Although the procedure initialize will change the value of the variable to 25, it will
only do that once the procedure is executed. In the meantime, the public global variable
upper_bound has the value of 10.
40. C. DROP PACKAGE BODY FRONT_OFFICE
Explanation There is no DROP PACKAGE SPECIFICATION command, and the reserved
words COMPILE and CASCADE aren't relevant to the DROP statement. The command
DROP PACKAGE BODY FRONT_OFFICE will remove the package body from the package
front_office and leave the package specification alone.
20
41. You want to create a trigger that will store the name of the Oracle schema that issues
any UPDATE statements against the PURCHASE_ORDERS table. You aren't
concerned with the actual records changed, only with the fact that an UPDATE was
issued. Which of the following is the best approach?
A. Create a BEFORE OR AFTER UPDATE trigger FOR EACH ROW.
B. Create a BEFORE UPDATE trigger FOR EACH STATEMENT.
C. Create a BEFORE OR AFTER UPDATE trigger, and use a WHEN clause to
limit the firing.
D. It cannot be done.
42. Consider the following code sample:
CREATE OR REPLACE TRIGGER GB_FLAG
BEFORE DELETE ON GUEST_BOOKINGS
DECLARE
stop_it EXCEPTION;
BEGIN
IF TO_CHAR(SYSDATE,'Dy') NOT IN ('Sat','Sun') THEN
COMMIT;
ELSE
RAISE stop_it;
END IF;
END;
/
Which of the following statements is true of this code?
A. It will produce a compilation error because of the attempt to declare an
exception.
B. It will not compile because there is no FOR EACH statement.
C. It will compile but will produce an execution error.
D. There is nothing wrong with this trigger.
43. An INSTEAD OF trigger can be used to: (Choose all that apply.)
A. Stop an UPDATE statement on a table according to the logic in the trigger
body.
B. Translate data on an INSERT statement to a table by using the
REFERENCING qualifiers.
C. Define how an INSERT statement will behave for a view.
D. Fire once for each statement on a view.
44. Which of the following can be included in the trigger body of an executable trigger?
(Choose all that apply.)
A. A user-defined variable defined with the %ROWTYPE declarative
B. A COMMIT statement
C. Calls to a stored procedure that contains a SAVEPOINT statement
D. An INSERT statement on the same table to which the trigger is assigned
45. You have created triggers with the following headers:
CREATE OR REPLACE TRIGGER PRODUCT_AUDIT
21
22
B. ACTION_TYPE
C. WHEN_CLAUSE
D. DESCRIPTION
Answers
23
Explanation Triggers are, by default, FOR EACH STATEMENT, unless specified as a FOR
EACH ROW. Remember that the reserved words FOR EACH STATEMENT are never actually
used.
49. C. ALTER TABLE EMPLOYEES ENABLE ALL TRIGGERS
Explanation A would be correct if the keyword COMPILE were used. B is incorrect; the
ENABLE ALL phrase is used with tables. D is missing the ALL reserved word. C is correct.
50. D. DESCRIPTION
Explanation Don't get irritated at me, the exam really has questions like this! The
DESRIPTION column combines information from many columns to display the trigger header,
including the database event. TRIGGER_NAME is the name of the trigger, ACTION_TYPE
only shows either PL/SQL or Call, and the WHEN_CLAUSE is the trigger's WHEN clause.
24
51. You have created a function called INVENTORY_QUEUE and stored it in the database
in a schema called DEPOT. Which of the following may now be successfully created in
the DEPOT schema? (Choose all that apply.)
A. A database trigger called INVENTORY_QUEUE
B. A stored package called MAINTENANCE containing a function called
INVENTORY_QUEUE
C. A stored package called INVENTORY_QUEUE containing a function called
MAINTENANCE
D. A stored procedure called INVENTORY_QUEUE
52. Consider the following code sample:
PROCEDURE COMPUTE_BONUS
IS
FETCH EMP.cur_employees INTO EMP.rec_employees;
DISTRIBUTE_BONUS(EMP.rec_employees.EMPLOYEE_ID,
EMP.v_bonus_rate);
END COMPUTE_BONUS;
Assuming all referenced objects are properly declared, which of the following can be
said about this code sample? (Choose all that apply.)
A. EMP is a package specification, and there is no package body.
B. EMP.cur_employees is definitely open before this code executes.
C. Another program unit could also issue a FETCH on EMP.cur_employees.
D. The procedure will not compile.
53. In the DEPOT schema, you have created a stored procedure with the following
header:
PROCEDURE BACK_ORDER(p_order_id IN NUMBER)
Which of the following procedures can now be stored in the DEPOT schema in
addition to the procedure you have just stored? (Choose all that apply.)
A. PROCEDURE BACK_ORDER(p_order_id IN VARCHAR2)
B. PROCEDURE BACK_ORDER(p_order_number IN NUMBER)
C. PROCEDURE BACK_ORDER(p_order_id IN NUMBER, p_order_date IN
DATE)
D. None of the above
54. In the DEPOT schema, you have created the following stored package specification:
PACKAGE WAREHOUSE AS
FUNCTION RESTOCK(p_product_id NUMBER) RETURN BOOLEAN;
END WAREHOUSE;
You decide to add an additional program unit to this package specification. Which of
the following function headers would be usable in the WAREHOUSE package as an
overloaded function?
A. FUNCTION RESTOCK(p_product_number NUMBER) RETURN BOOLEAN;
B. FUNCTION RESTOCK(p_product_id VARCHAR2) RETURN BOOLEAN;
C. FUNCTION RESTOCK(p_product_id INTEGER) RETURN BOOLEAN;
D. FUNCTION RESTOCK(p_product_id NUMBER) RETURN VARCHAR2;
25
55. Which of the following are valid purity levels? (Choose all that apply.)
A. WPNS
B. WSDN
C. RDSN
D. WNDS
56. Consider the following package body:
PACKAGE BODY GUEST_TRACKING AS
CURSOR cur_cruises RETURN rec_cruises IS
SELECT CRUISE_ID, CRUISE_NAME
FROM
CRUISES;
BEGIN
SELECT FIRST_NAME || ', ' || LAST_NAME GUEST_NAME
INTO
GUEST_TRACKING.GUEST_NAME
FROM
GUESTS
WHERE
GUEST_ID = PARMS.guest_id;
END GUEST_TRACKING;
Assuming all referenced constructs are properly declared, which of the following
statements are true about this package body? (Choose all that apply.)
A. It will not compile.
B. It will not execute.
C. It should be assigned the RNPS purity level.
D. It cannot be assigned the RNPS purity level.
57. Which of the following are acceptable to include in the RETURN statement of a
CURSOR statement? (Choose all that apply.)
A. A programmer-defined record variable
B. A set of variables, in the same order of the columns that are in the SELECT
statement
C. A set of variables, in any order, as long as it has the same number of columns
in the SELECT statement
D. A programmer-defined type
58. Consider the following code sample:
PACKAGE BODY PARM_LIST AS
CURSOR cur_port RETURN rec_port_type
IS
SELECT
PORT_ID, PORT_NAME
FROM
PORTS
ORDER BY PORT_NAME;
END PARM_LIST;
Assuming any referenced constructs are properly declared, which of the following
statements are true about this code sample? (Choose all that apply.)
A. This is a package body.
B. The cursor cur_port is a public construct.
C. The cursor cur_port is a private construct.
26
27
VARCHAR2.
55. D. WNDS
Explanation The four purity levels are WNDS, RNDS, WNPS, and RNPS. The answers for A,
B, and C are all made up. But get ready for thatthe exam asks questions like this.
56. D. It cannot be assigned the RNPS purity level.
Explanation The reference to PARMS.guest_id in the package initialization section is a
packaged construct in another package. This package body would not compile successfully if
the RNPS purity level were asserted for this package initialization section.
57. D. A programmer-defined type
Explanation Even though a FETCH statement will fetch into a set of variables, the RETURN
statement doesn't accept them. A programmer-defined type or a %ROWTYPE declaration is
required.
58. A. This is a package body.
Explanation This is clearly a package body, according to the first line that declares it.
However, you cannot tell if the cursor is private or public from this declaration alone. You must
see the package specification to know for sure. If the cursor header is included in the package
specification, then it's public; otherwise, it's private. The package body syntax here is fine, so
D is wrong.
59. A. A packaged procedure stored in the database
Explanation A procedure that is stored in the database cannot call any client-side program
units.
60. C. It documents a function's intended purpose.
Explanation The PRAGMA RESTRICT_REFERENCES statement is a compiler directive and
has no bearing on the actual execution of the program unit that is restricted. It is not required
for any functions, but is highly recommended to avoid potential trouble with the execution of
functions, especially functions that will be invoked from within SQL statements or remote
databases.
28
29
68. What can you not do with a batch job in the database?
A. Remove it from the queue.
B. Schedule it for a specific time and know that it will definitely execute at that
specific time no matter what.
C. Change its scheduled execution interval after it has already been submitted to
the queue.
D. Export it to another database.
69. What command in SQL*Plus causes the SQL*Plus interface to get information that
DBMS_OUTPUT sends to the output buffer and show it to the screen?
A. SET OUTPUT BUFFER ON
B. SET SERVER ON
C. SET SERVEROUTPUT ON
D. SET BUFFER ON
70. A pipe name created with DBMS_PIPE is unique to a
A. Procedure
B. Stored database procedure
C. Schema
D. Instance
Answers
30
Explanation This is exactly what DBMS_PIPE is designed to do. Sending messages through
pipes enables you to communicate directly with another session.
66. B. PACK_MESSAGE
Explanation BIND_VARIABLE and EXECUTE are DBMS_SQL procedures. PACK_ITEM is
not real.
67. A, D. A: DBMS_SQL D: A standard PL/SQL block
Explanation DBMS_SQL enables you to send any SQL statement, including SELECT
statements, to the database. Remember that you can do that with standard PL/SQL code
anyway. There is no Oracle-Corporation-supplied package as DBMS_SELECT at the time of
this writing, and DBMS_DDL only works with certain DDL statements.
68. B. Schedule it for a specific time and know that it will definitely execute at that specific time no
matter what.
Explanation The scheduled execution time is influenced by when the job queue wakes up
and looks for jobs to execute. This, in turn, is defined by the database initialization parameter
JOB_QUEUE_INTERVAL.
69. C. SET SERVEROUTPUT ON
Explanation The DBMS_OUTPUT package sends information to the output buffer, but
whether or not SQL*Plus displays this information on the screen depends on the SQL*Plus
session parameter SERVEROUTPUT, which must be ON. You can set any session parameter
value within SQL*Plus with the SET command; thus, it is SET SERVEROUTPUT ON.
70. D. Instance
Explanation The procedure UNIQUE_SESSION_NAME is specifically designed to assist in
the process of making sure you come up with a pipe name that is unique to a given instance.
Because multiple sessions within an instance can communicate with each other, the pipe
name must be global to the entire instance in order for the sessions to locate the pipe.
31
71. Which of the following is an SQL*Plus buffer editor command? (Choose all that apply.)
A. LIST
B. DELETE
C. 1
D. PUT
72. Consider the following code sample:
CREATE OR REPLACE PROCEDURE ASSIGN_APP_NAME
(p_app_id IN VARCHAR2) IS
BEGIN
SELECT APP_NAME
INTO
PARMS.v_app_name
FROM
APP
WHERE
APP_ID = p_app_id;
DBMS_OUTPUT.PUT_LINE('Done');
END;
/
You submit this code to the SQL*Plus interface. What are the contents of the buffer?
(Choose the single best answer.)
A. It depends on whether this procedure compiled successfully or not.
B. SELECT APP_NAME INTO PARMS.v_app_name FROM APP WHERE APP_ID
= p_app_id
C. DBMS_OUTPUT.PUT_LINE(Done);
D. The entire statement, from CREATE to END;
73. You have used a text editor to save the CREATE PROCEDURE
ASSIGN_APP_NAME statement from Question 2 in a single text file. Which of the
following commands can be used from within SQL*Plus to load the contents of this
file? (Choose all that apply.)
A. EXEC
B. RUN
C. GET
D. START
74. In the Object Navigator, when an asterisk appears to the right of the name of a
program unit, what does it indicate? (Choose all that apply.)
A. The program unit is on the client side.
B. The program unit is not valid, and needs to be compiled.
C. The program unit is a function.
D. The program unit includes parameters.
75. In Procedure Builder's Object Navigator, what does the References node display for a
given program unit?
A. Other program units that reference this program unit.
B. Program units that this program unit references.
C. A list of online help resources for programming in PL/SQL.
D. There is no such node.
76. In Procedure Builder's Object Navigator, you expand the Database Objects node and
32
discover four subnodes. Which of the following statements are true? (Choose all that
apply.)
A. There are four tables in the schema.
B. There are four schemas in the database.
C. Procedure Builder is not connected to the database.
D. Procedure Builder is connected to the database.
77. In the Procedure Builder Object Navigator, the difference between the nodes PL/SQL
Libraries and Attached Libraries is that
A. You can edit PL/SQL Libraries, but you cannot edit Attached Libraries.
B. You can execute PL/SQL Libraries, but you cannot execute Attached Libraries.
C. PL/SQL Libraries are on the client and Attached Libraries are on the server.
D. There is no difference.
78. You can use Procedure Builder to move program units ____________. (Choose all
that apply.)
A. From one schema in the database to another schema in the database
B. From one attached library on the client to a schema in the database
C. From one attached library on the client to another attached library on the client
D. From one schema in the database to an attached library on the client
79. When Not Compiled in the lower-right corner of the PL/SQL Editor appears, this
indicates that
A. The program unit in the editor has never been compiled.
B. The code in the program unit cannot be compiled.
C. You just attempted to compile the program unit, but the attempt was
unsuccessful.
D. None of the above.
80. You can use Procedure Builder to create the following:
A. Database triggers
B. Package specifications
C. Stored functions
D. Client-side procedures in a library
Answers
33
buffer. GET will load a file and will perform successfully if the file contains one single
statement, which this file will contain. START can be used to load and execute any file
containing one or more SQL statements.
74. B. The program unit is not valid, and needs to be compiled.
Explanation The asterisk means that the program unit has a STATUS of INVALID. It doesn't
matter if the program unit is a function or if it has parameters.
75. B. Program units that this program unit references
Explanation The References node shows program units that this particular program unit
references, such as procedures and functions and packages that it invokes.
76. B, D. B: There are four schemas in the database. D: Procedure Builder is connected to the
database.
Explanation The Database Objects node will not be activated at all unless Procedure Builder
is connected to the database. When you expand Database Objects, you are first presented
with an alphabetic list of schemas. You don't find tables until you expand the schema nodes.
77. A. You can edit PL/SQL Libraries, but you cannot edit Attached Libraries.
Explanation Any PL/SQL library can be included under either node. You can even open a
single library under both nodes simultaneously. The PL/SQL Library is where a library appears
that you have opened for editing. The Attached Libraries node is where a library appears that
you have attached for execution.
78. A, B, C, D. A: From one schema in the database to another schema in the database B: From
one attached library on the client to a schema in the database C: From one attached library
on the client to another attached library on the client D: From one schema in the database to
an attached library on the client
Explanation All are trueall can be displayed in the Object Navigator so they all will support
the capability to copy a program unit from one location to the other.
79. D. None of the above.
Explanation The Not Compiled message means that the code has not been compiled since it
was last changed. A change could consist of one blank space typed in a comment. If a
compilation was just attempted and was unsuccessful, Compiled with Errors will appear.
80. A, B, C, D. A: Database triggers B: Package specifications C: Stored functions D: Client-side
procedures in a library
Explanation You can create them all!
34
35
36
Regards
[email protected]
37