You are on page 1of 139

The following code declares a PL/SQL record with the same structure as a row of the

departments table. True or False?

DECLARE

v_dept_rec departments%ROWTYPE;

...

Mark for Review

(1) Points

True (*)

False

[Correct] Correct

2. Which of the following statements about user-defined PL/SQL records is NOT


true? Mark for Review

(1) Points

It can be used as an OUT parameter in a package procedure.

It is not the same as a row in a database table.


It can be defined as NOT NULL.

It can be a component of another PL/SQL record.

It must contain one or more components, but all the components must have scalar datatypes.
(*)

6 Lesson 1.

3. Which of the following will successfully create a record type containing two
fields, and a record variable of that type? Mark for Review

(1) Points

TYPE person_type IS RECORD

(l_name VARCHAR2(20),

gender CHAR(1));

person_rec TYPE person_type;


TYPE person_type IS RECORD

(l_name VARCHAR2(20),

gender CHAR(1));

person_rec person_type;

(*)

TYPE person_type IS (l_name VARCHAR2(20),

gender CHAR(1));

person_rec TYPE person_type;

TYPE person_type IS (l_name VARCHAR2(20),

gender CHAR(1));

person_rec person_type;

6 Lesson 1.

Section 1

(Answer all questions in this section)

1. To declare an INDEX BY table, we must first declare a type and then declare a
collection variable of that type. True or False? Mark for Review
(1) Points

True (*)

False

6 Lesson 2.

2. Which of the following methods can be used to reference elements of an INDEX


BY table? (Choose three.) Mark for Review

(1) Points

(Choose all correct answers)

DROP

FIRST (*)

EXISTS (*)
COUNT (*)

PREVIOUS

6 Lesson 2.

3. Which of the following successfully declares an INDEX BY table of records which


could be used to store copies of complete rows from the departments table? Mark for Review

(1) Points

DECLARE

TYPE t_depttab IS TABLE OF departments%ROWTYPE

INDEX BY BINARY_INTEGER;

(*)

DECLARE

TYPE t_depttab IS TABLE OF departments%TYPE

INDEX BY BINARY_INTEGER;

DECLARE
TYPE t_depttab IS TABLE OF departments%ROWTYPE

INDEX BY NUMBER;

DECLARE

TYPE t_depttab IS INDEX BY TABLE OF departments%ROWTYPE

INDEX BY BINARY_INTEGER;

6 Lesson 2.

4. What is the largest number of elements (i.e., records) that an INDEX BY table of
records can contain? Mark for Review

(1) Points

100

4096

32767
Many millions of records because a BINARY_INTEGER or PLS_INTEGER can have a very large
value (*)

None of the above

6 Lesson 2.

5. Which of these PL/SQL data structures could store a complete copy of the
employees table, i.e., 20 complete table rows? Mark for Review

(1) Points

An INDEX BY table of records (*)

An explicit cursor based on SELECT * FROM employees;

A record

An INDEX BY table
6 Lesson 2.

6. Which of these PL/SQL data structures can NOT store a collection? Mark
for Review

(1) Points

An INDEX BY table of records

An INDEX BY table indexed by BINARY_INTEGER

An INDEX BY table indexed by PLS_INTEGER

A PL/SQL record (*)

6 Lesson 2.

Section 1

(Answer all questions in this section)

1. Which of the following is NOT a predefined Oracle Server error? Mark for
Review

(1) Points
e_sal_too_high EXCEPTION; (*)

DUP_VAL_ON_INDEX

TOO_MANY_ROWS

ZERO_DIVIDE

NO_DATA_FOUND

7 Lesson 2.

2. Which of the following best describes a predefined Oracle Server error? Mark
for Review

(1) Points

Has a standard Oracle error number and a standard name which can be referenced in the
EXCEPTION section (*)
Has a standard Oracle error number but must be declared and named by the PL/SQL
programmer

Is associated with an Oracle error number using PRAGMA EXCEPTION_INIT

Is not raised automatically but must be declared and raised explicitly by the PL/SQL programmer

7 Lesson 2.

3. Which kind of error can NOT be handled by PL/SQL? Mark for Review

(1) Points

Non-predefined Oracle Server errors

Predefined Oracle Server errors

Syntax errors (*)

User-defined errors
7 Lesson 2.

4. Examine the following code. At Line A, you want to raise an exception if the
employee's manager_id is null. What kind of exception is this?

DECLARE

v_mgr_id employees.manager_id%TYPE;

BEGIN

SELECT manager_id INTO v_mgr_id FROM employees

WHERE employee_id = 100;

IF v_mgr_id IS NULL THEN

-- Line A

END IF;

...

Mark for Review

(1) Points

A non-predefined Oracle server exception

A constraint violation

A NO_DATA_FOUND exception
A predefined Oracle Server exception

A user-defined exception (*)

[Correct] Correct

5. How would you trap Oracle Server exception ORA-01403: no data found?
Mark for Review

(1) Points

WHEN NO_DATA_FOUND THEN ... (*)

WHEN NO DATA FOUND THEN ...

WHEN SQL%ROWCOUNT=0 THEN ...

WHEN ORA-01403 THEN ...


7 Lesson 2.

6. No employees exist whose salary is less than 2000. Which exception handlers
would successfully trap the exception that will be raised when the following code is executed? (Choose
two.)

DECLARE

v_mynum NUMBER := 10;

v_count NUMBER;

BEGIN

SELECT COUNT(*) INTO v_count FROM employees

WHERE salary < 2000;

v_mynum := v_mynum / v_count;

EXCEPTION ...

END;

Mark for Review

(1) Points

(Choose all correct answers)

OTHERS (*)

SQL%ROWCOUNT = 0
NO_DATA_FOUND

ZERO_DIVIDE (*)

OTHER

7 Lesson 2.

7. What is the correct syntax to associate an exception named EXCEPNAME with


the non-predefined Oracle Server error ORA-02292? Mark for Review

(1) Points

PRAGMA EXCEPTION_INIT (excepname, -2292) (*)

SQLCODE (-2292, excepname);

RAISE_APPLICATION_ERROR (-2292, excepname);

WHEN (-2292, excepname) THEN ?


7 Lesson 2.

8. An ORA-1400 exception is raised if an attempt is made to insert a null value into


a NOT NULL column. DEPARTMENT_ID is the primary key of the DEPARTMENTS table. What will happen
when the following code is executed?

DECLARE

e_not_null EXCEPTION;

BEGIN

PRAGMA EXCEPTION_INIT(e_not_null, -1400);

INSERT INTO departments (department_id, department_name)

VALUES(null, 'Marketing');

EXCEPTION

WHEN e_not_null THEN

DBMS_OUTPUT.PUT_LINE('Cannot be null');

END;

Mark for Review

(1) Points

The code will not execute because PRAGMA EXCEPTION_INIT must be coded in the DECLARE
section. (*)

The code will not execute because the syntax of PRAGMA EXCEPTION_INIT is wrong.
The exception will be raised and "Cannot be null" will be displayed.

The code will not execute because the syntax of the INSERT statement is wrong.

7 Lesson 2.

9. Examine the following code. The UPDATE statement will raise an ORA-02291
exception.

BEGIN

UPDATE employees SET department_id = 45;

EXCEPTION

WHEN OTHERS THEN

INSERT INTO error_log_table VALUES (SQLCODE);

END;

What will happen when this code is executed?

Mark for Review

(1) Points

The code will execute and insert error number 02291 into error_log_table.
The code will fail because we access error message numbers by using SQLERRNUM, not
SQLCODE.

The code will fail because SQLCODE has not been declared.

The code will fail because we cannot use functions like SQLCODE directly in a SQL statement. (*)

[Correct] Correct

10. Which type of exception MUST be explicitly raised by the PL/SQL programmer?
Mark for Review

(1) Points

User-defined exceptions (*)

Predefined Oracle server errors such as TOO_MANY_ROWS

Non-predefined Oracle server errors such as ORA-01203

All of the above


7 Lesson 2.

11. A PL/SQL block executes and an Oracle Server exception is raised. Which of the
following contains the text message associated with the exception? Mark for Review

(1) Points

SQLCODE

SQLERRM (*)

SQL%MESSAGE

SQL_MESSAGE_TEXT

[Correct] Correct

12. Which one of the following events would implicitly raise an exception? Mark
for Review
(1) Points

A SELECT statement returns exactly one row.

The PL/SQL programmer mis-spells the word BEGIN as BEGAN.

A database constraint is violated. (*)

An UPDATE statement modifies no rows.

7 Lesson 2.

1. Which of the following is NOT an advantage of including an exception handler in a PL/SQL block?
Mark for Review

(1) Points

Avoids costly and time-consuming correction of mistakes

Code is more readable because error-handling routines can be written in the same block in
which the error occurred
Prevents errors from being propagated back to the calling environment

Prevents errors from occurring (*)

7 Lesson 1.

2. Which of the following best describes a PL/SQL exception? Mark for


Review

(1) Points

A compile-time error occurs because the PL/SQL code references a non-existent table.

An error occurs during the execution of the block, which disrupts the normal operation of the
program. (*)

The programmer forgets to declare a cursor while writing the PL/SQL code.

A user enters an invalid password while trying to log on to the database.


[Correct] Correct

3. Which of these exceptions can be handled by an EXCEPTION section in a PL/SQL


block? Mark for Review

(1) Points

An attempt is made to divide by zero

A SELECT statement returns no rows

Any other kind of exception that can occur within the block

All of the above (*)

None of the above

7 Lesson 1.
4. Only one exception at a time can be raised during one execution of a PL/SQL
block. True or False? Mark for Review

(1) Points

True (*)

False

[Correct] Correct

5. Which of the following EXCEPTION sections is constructed correctly? (Choose


three.) Mark for Review

(1) Points

(Choose all correct answers)

EXCEPTION

WHEN OTHERS THEN statement_1;

END;

(*)
EXCEPTION

WHEN OTHERS THEN statement_1;

WHEN NO_DATA_FOUND THEN statement_2;

END;

EXCEPTION

WHEN NO_DATA_FOUND THEN statement_1;

WHEN NO_DATA_FOUND THEN statement_2;

WHEN OTHERS THEN statement_3;

END;

EXCEPTION

WHEN NO_DATA_FOUND THEN statement_1;

WHEN OTHERS THEN statement_2;

END;

(*)

EXCEPTION

WHEN TOO_MANY_ROWS THEN statement_1;

END;

(*)
7 Lesson 1.

6. The following EXCEPTION section is constructed correctly. True or False?

EXCEPTION

WHEN ZERO_DIVIDE OR TOO_MANY_ROWS OR NO_DATA_FOUND

THEN statement_1;

statement_2;

WHEN OTHERS

THEN statement_3;

END;

Mark for Review

(1) Points

True (*)

False

[Correct] Correct
7. Which of the following are NOT good practice guidelines for exception
handling? (Choose two.) Mark for Review

(1) Points

(Choose all correct answers)

Include a WHEN OTHERS handler as the first handler in the exception section. (*)

Allow exceptions to propagate back to the calling environment. (*)

Handle specific named exceptions where possible, instead of relying on WHEN OTHERS.

Test your code with different combinations of data to see what potential errors can happen.

Use an exception handler whenever there is any possibility of an error occurring.

7 Lesson 1.

8. Examine the following code. Why does this exception handler not follow good
practice guidelines? (Choose two.)
DECLARE

v_dept_name departments.department_name%TYPE;

BEGIN

SELECT department_name INTO v_dept_name FROM departments

WHERE department_id = 75;

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('A select returned more than one row');

END;

Mark for Review

(1) Points

(Choose all correct answers)

The exception handler should COMMIT the transaction.

department_id 75 does not exist in the departments table.

The exception section should include a WHEN TOO_MANY_ROWS exception handler. (*)

You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.

The exception handler should test for the named exception NO_DATA_FOUND. (*)
7 Lesson 1.

1. What is a user-defined exception? Mark for Review

(1) Points

An exception which is not raised automatically by the Oracle server, but must be declared and
raised explicitly by the PL/SQL programmer. (*)

An exception which has a predefined Oracle error number but no predefined name.

A predefined Oracle server exception such as NO_DATA_FOUND.

An exception handler which the user (the programmer) includes in the EXCEPTION section.

7 Lesson 3.

2. What is the datatype of a user-defined exception? Mark for Review

(1) Points
BOOLEAN

VARCHAR2

EXCEPTION (*)

NUMBER

None of the above

[Correct] Correct

3. What is wrong with the following code?

BEGIN

UPDATE employees SET salary = 20000

WHERE job_id = 'CLERK';

IF SQL%ROWCOUNT = 0 THEN

RAISE NO_DATA_FOUND; -- Line A

END IF;

EXCEPTION
WHEN NO_DATA_FOUND THEN

DBMS_OUTPUT.PUT_LINE('No employee was updated');

END;

Mark for Review

(1) Points

You cannot use SQL%ROWCOUNT in conditional control statements such as IF or CASE.

NO_DATA_FOUND has not been DECLAREd.

Line A should be: HANDLE NO_DATA_FOUND

You cannot explicitly raise predefined Oracle Server errors such as NO_DATA_FOUND.

Nothing is wrong; the code will execute correctly. (*)

7 Lesson 3.

4. What will be displayed when the following code is executed?

DECLARE
e_myexcep EXCEPTION;

BEGIN

DBMS_OUTPUT.PUT_LINE('Message 1');

RAISE e_myexcep;

DBMS_OUTPUT.PUT_LINE('Message 2');

EXCEPTION

WHEN e_myexcep THEN

DBMS_OUTPUT.PUT_LINE('Message 3');

RAISE e_myexcep;

DBMS_OUTPUT.PUT_LINE('Message 4');

END;

Mark for Review

(1) Points

Message 1

Message 3

The code will not execute because it contains at least one syntax error.

The code will execute but will return an unhandled exception to the calling environment.

(*)
Message 1

Message 2

Message 3

Message 4

Message 1

Message 3

Message 4

7 Lesson 3.

5. The following line of code is correct. True or False?

RAISE_APPLICATION_ERROR(-21001,'My error message'); Mark for Review

(1) Points

True

False (*)
[Correct] Correct

6. How are user-defined exceptions raised ? Mark for Review

(1) Points

By PRAGMA EXCEPTION_INIT

By DECLARE e_my_excep EXCEPTION;

By RAISE exception_name; (*)

None of the above. They are raised automatically by the Oracle server.

7 Lesson 3.

7. The following three steps must be performed to use a user-defined exception: -


Raise the exception - Handle the exception - Declare the exception In what sequence must these steps
be performed? Mark for Review

(1) Points
Declare, Raise, Handle (*)

The steps can be performed in any order.

Handle, Raise, Declare

Raise, Handle, Declare

7 Lesson 3.

8. You want to display your own error message to the user. What is the correct
syntax to do this? Mark for Review

(1) Points

RAISE application_error;

RAISE_APPLICATION_ERROR(20001, 'My own message');

RAISE_APPLICATION_ERROR('My own message', -20001);


RAISE_APPLICATION_ERROR (-20001, 'My own message'); (*)

7 Lesson 3.

1. Predefined Oracle Server exceptions such as NO_DATA_FOUND can be raised


automatically in inner blocks and handled in outer blocks. True or False? Mark for Review

(1) Points

True (*)

False

[Correct] Correct

2. Non-predefined Oracle Server errors (associated with Oracle error numbers by


PRAGMA EXCEPTION_INIT) can be declared and raised in inner blocks and handled in outer blocks. True
or False? Mark for Review

(1) Points
True

False (*)

7 Lesson 4.

3. What will happen when the following code is executed?

DECLARE

e_outer_excep EXCEPTION;

BEGIN

DECLARE

e_inner_excep EXCEPTION;

BEGIN

RAISE e_outer_excep;

END;

EXCEPTION

WHEN e_outer_excep THEN

DBMS_OUTPUT.PUT_LINE('Outer raised');

WHEN e_inner_excep THEN

DBMS_OUTPUT.PUT_LINE('Inner raised');

END;

Mark for Review

(1) Points
The code will fail to compile because e_inner_excep was declared but never RAISEd.

The code will fail to compile because e_inner_excep cannot be referenced in the outer block. (*)

The code will execute successfully and 'Outer Raised' will be displayed.

The code will propagate the e_outer_excep back to the calling environment (Application
Express).

[Correct] Correct

4. What will happen when the following code is executed?

DECLARE

e_excep1 EXCEPTION;

e_excep2 EXCEPTION;

BEGIN

RAISE e_excep1;

EXCEPTION

WHEN e_excep1 THEN BEGIN

RAISE e_excep2; END;

END;

Mark for Review


(1) Points

It will fail to compile because you cannot have a subblock inside an exception section.

It will fail to compile because e_excep1 is out of scope in the subblock.

It will fail to compile because you cannot declare more than one exception in the same block.

It will compile successfully and return an unhandled e_excep2 to the calling environment. (*)

7 Lesson 4.

5. There are three employees in department 90. What will be displayed when this
code is executed?

DECLARE

v_last_name employees.last_name%TYPE;

BEGIN

DBMS_OUTPUT.PUT_LINE('Message 1');

BEGIN

SELECT last_name INTO v_last_name

FROM employees WHERE department_id = 90;


DBMS_OUTPUT.PUT_LINE('Message 2');

END;

DBMS_OUTPUT.PUT_LINE('Message 3');

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('Message 4');

END;

Mark for Review

(1) Points

Message 1

Message 3

Message 4

Message 1

Message 4

(*)

Message 1

An unhandled exception will be propagated back to the calling environment.


None of the above

7 Lesson 4.

6. What will be displayed when the following code is executed?

<<outer>>

DECLARE

v_myvar NUMBER;

BEGIN

v_myvar := 25;

DECLARE

v_myvar NUMBER := 100;

BEGIN

outer.v_myvar := 30;

v_myvar := v_myvar / 0;

outer.v_myvar := 35;

END;

v_myvar := 40;

EXCEPTION

WHEN ZERO_DIVIDE THEN

DBMS_OUTPUT.PUT_LINE(v_myvar);

END;
Mark for Review

(1) Points

30 (*)

100

40

35

25

7 Lesson 4.

Section 1

(Answer all questions in this section)

1. Which of the following are characteristics of anonymous PL/SQL blocks but not
PL/SQL subprograms? (Choose three.) Mark for Review

(1) Points
(Choose all correct answers)

Are unnamed (*)

Can begin with the keyword DECLARE (*)

Can take parameters

Are stored in the database

Are compiled every time they are executed (*)

8 Lesson 1.

2. Subprograms and anonymous blocks can be called by other applications. True or


False? Mark for Review

(1) Points

True
False (*)

8 Lesson 1.

3. Which of the following are benefits of using PL/SQL subprograms rather than
anonymous blocks? (Choose three.) Mark for Review

(1) Points

(Choose all correct answers)

Easier code maintenance (*)

Better data security (*)

Code reuse (*)

Do not need to define exceptions

Stored externally
8 Lesson 1.

4. PL/SQL subprograms, unlike anonymous blocks, are compiled each time they
are executed. True or False? Mark for Review

(1) Points

True

False (*)

8 Lesson 1.

5. Procedures are generally used to perform what? Mark for Review

(1) Points

A SELECT statement

An action (*)
A return of values

All of the above

None of the above

[Correct] Correct

6. A programmer wants to create a PL/SQL procedure named MY_PROC. What will


happen when the following code is executed?

CREATE OR REPLACE PROCEDURE my_proc IS

v_empid employees.empid%TYPE;

BEGIN

SELECT employee_id INTO v_empid FROM employees

WHERE region_id = 999;

DBMS_OUTPUT.PUT_LINE('The salary is: ' || v_salary);

Mark for Review

(1) Points
The statement will fail because you cannot declare variables such as v_empid inside a
procedure.

The statement will fail because the last line of code should be END my_proc; (*)

The statement will raise a NO_DATA_FOUND exception because region_id 999 does not exist.

[Correct] Correct

7. Which of the following keywords MUST be included in every PL/SQL procedure


definition? (Choose two.) Mark for Review

(1) Points

(Choose all correct answers)

REPLACE

END (*)

BEGIN (*)
DECLARE

EXCEPTION

8 Lesson 1.

8. A stored PL/SQL procedure can be invoked from which of the following?

A PL/SQL anonymous block

A calling application

A SELECT statement

Another PL/SQL procedure

Mark for Review

(1) Points

A and C

A, B, and D (*)

A and B
A only

B and C

[Correct] Correct

9. A stored procedure add_dept may be invoked by the following command in


Application Express. True or False?

BEGIN

add_dept;

END;

Mark for Review

(1) Points

True (*)

False
[Correct] Correct

10. The following are the steps involved in creating, and later modifying and re-
creating, a PL/SQL procedure in Application Express. Which step is missing?

Type the procedure code in the SQL Commands window

Click on the "Save" button and save the procedure code

Retrieve the saved code from "Saved SQL" in SQL Commands

Modify the code in the SQL Commands window

Execute the code to re-create the procedure

Mark for Review

(1) Points

Enter parameters and data type

Exe ute the procedure from USRE_SOURCE data dictionary view

Execute the code to create the procedure (*)

Invoke the procedure from an anonymous block


8 Lesson 1.

11. When modifying procedure code, the procedure code statement must be re-
executed to validate and store it in the database. True or False? Mark for Review

(1) Points

True (*)

False

[Correct] Correct

12. A nested subprogram can be called from the main procedure or from the calling
environment. True or False? Mark for Review

(1) Points

True

False (*)
8 Lesson 1.

13. Why will the following procedure fail?

CREATE OR REPLACE PROCEDURE mainproc

...

IS

PROCEDURE subproc (...) IS BEGIN

...

BEGIN

...

subproc (...);

...

END;

Mark for Review

(1) Points

Procedure main proc must use the keyword AS not IS

Procedure mainproc does not need the keyword BEGIN

Procedure subproc does not need the keyword BEGIN


Procedure subproc does not have an END; statement (*)

8 Lesson 1.

1. Which of the following best describes the difference between a parameter and
an argument? Mark for Review

(1) Points

They are both names of variables. A parameter is passed into the procedure, while an argument
is passed out of the procedure.

A parameter is the name of a variable, while an argument is the datatype of that variable.

A parameter is a variable that accepts a value that is passed to it, while an argument is the value
that is passed. (*)

There is no difference; parameters and arguments are the same thing.

8 Lesson 2.
2. What is the correct syntax to create procedure MYPROC that accepts two
number parameters X and Y? Mark for Review

(1) Points

CREATE PROCEDURE myproc (x NUMBER, y NUMBER) IS ... (*)

CREATE PROCEDURE (x NUMBER, y NUMBER) myproc IS ...

CREATE PROCEDURE myproc IS (x NUMBER, y NUMBER) ...

CREATE PROCEDURE IS myproc (x NUMBER, y NUMBER)

8 Lesson 2.

3. Which of the following can be used as an argument for a procedure parameter?


Mark for Review

(1) Points

The name of a variable


A literal value

An expression

All of the above (*)

None of the above

8 Lesson 2.

4. A procedure has been created as:

CREATE PROCEDURE myproc

(p_left NUMBER, p_right NUMBER)

IS BEGIN ....

You want to call the procedure from an anonymous block. Which of the following calls is valid?

Mark for Review

(1) Points
myproc(p_left, p_right);

myproc(v_left, v_right);

myproc(v_left, 30);

All of the above (*)

8 Lesson 2.

5. What is the purpose of using parameters with stored procedures? Mark


for Review

(1) Points

They prevent the procedure from modifying data in the database.

They allow values to be passed between the calling environment and the procedure. (*)

They count the number of exceptions raised by the procedure.


They speed up the execution of the procedure.

8 Lesson 2.

6. Procedure SUBPROC was created as:

CREATE PROCEDURE subproc

(p_param VARCHAR2)

IS BEGIN ...

You invoke the procedure by:

DECLARE

v_param VARCHAR2(20) := 'Smith';

BEGIN

subproc(v_param);

END;

Which of the following is the actual parameter?

Mark for Review

(1) Points

p_param
v_param (*)

Smith'

None of the above

8 Lesson 2.

7. Which one of the following statements about formal and actual parameters is
true? Mark for Review

(1) Points

Formal and actual parameters must have the same name.

Formal and actual parameters must have different names.

A formal parameter is declared within the called procedure, while an actual parameter is
declared in the calling environment. (*)
An actual parameter is declared within the called procedure.

8 Lesson 2.

8. Procedure TESTPROC accepts one parameter P1, whose value is up to 1000


characters in length. Which one of the following declares this parameter correctly? Mark for
Review

(1) Points

CREATE PROCEDURE testproc

(p1 VARCHAR2(100) )

IS

BEGIN ....

CREATE PROCEDURE testproc

IS

p1 VARCHAR2(100);

BEGIN ....

CREATE PROCEDURE testproc


DECLARE

p1 VARCHAR2(100);

BEGIN ....

CREATE PROCEDURE testproc

p1 VARCHAR2

IS

BEGIN ....

CREATE PROCEDURE testproc

(p1 VARCHAR2)

IS

BEGIN ....

(*)

8 Lesson 2.

9. You want to create a procedure which accepts a single parameter. The


parameter is a number with a maximum value of 9999.99. Which of the following is a valid declaration
for this parameter? Mark for Review

(1) Points
(v_num NUMBER(6,2))

(v_num NUMBER) (*)

(v_num)

(v_num NUMBER(4,2))

[Correct] Correct

1. What are the three parameter modes for procedures? Mark for Review

(1) Points

IN, OUT, IN OUT (*)

R(ead), W(rite), A(ppend)

CONSTANT, VARIABLE, DEFAULT


COPY, NOCOPY, REF

8 Lesson 3.

2. If you don't specify a mode for a parameter, what is the default mode? Mark
for Review

(1) Points

OUT

IN (*)

COPY

DEFAULT

R(ead)
8 Lesson 3.

3. Which of the following statements about IN OUT parameters are true? (Choose
two.) Mark for Review

(1) Points

(Choose all correct answers)

The data type for the parameter must be VARCHAR2.

The parameter value passed into the subprogram is always returned unchanged to the calling
environment.

The parameter value can be returned as the original unchanged value. (*)

The parameter value can be returned as a new value that is set within the procedure. (*)

8 Lesson 3.

4. When creating a procedure, where in the code must the parameters be listed?
Mark for Review
(1) Points

After the procedure name (*)

After the keyword IS or AS

Before the procedure name

After the keyword PROCEDURE

8 Lesson 3.

5. A procedure is invoked by this command:

myproc('Smith',100,5000);

What is the method of passing parameters used here?

Mark for Review

(1) Points
Positional (*)

Named

A combination of positional and named

None of the above

8 Lesson 3.

6. A procedure is invoked by this command:

myproc('Smith',salary=>5000);

What is the method of passing parameters used here?

Mark for Review

(1) Points

Positional
Named

A combination of positional and named (*)

None of the above

[Correct] Correct

7. Which kind of parameters cannot have a DEFAULT value? Mark for


Review

(1) Points

OUT (*)

IN

CONSTANT

R(ead)
W(rite)

8 Lesson 3.

8. The following procedure has been created:

CREATE OR REPLACE PROCEDURE myproc

(p_p1 NUMBER, p_p2 VARCHAR2)

IS BEGIN ...

Which one of the following calls to the procedure will NOT work?

Mark for Review

(1) Points

myproc(80, 'Smith');

myproc(p_p1 => 80, 'Smith'); (*)

myproc(80, p_p2 => 'Smith');


myproc(p_p1 => 80, p_p2 => 'Smith');

8 Lesson 3.

9. Three IN parameters for procedure ADD_EMPLOYEE are defined as:

(p_name VARCHAR2 ,

p_salary NUMBER := 1000,

p_hired DATE DEFAULT SYSDATE)

The procedure is invoked by:

add_employee('Jones');

What is the value of P_SALARY when the procedure starts to execute?

Mark for Review

(1) Points

NULL

1000 (*)

The procedure will not compile because P_SALARY should have been coded as DEFAULT 1000
The call will fail because P_SALARY is a required parameter

8 Lesson 3.

10. What will happen when the following procedure is called as format_phone
(8005551234)?

CREATE OR REPLACE PROCEDURE format_phone

(p_phone_no IN OUT VARCHAR2) IS

BEGIN

p_phone_no := SUBSTR(p_phone_no,1,3) ||

'.' || SUBSTR(p_phone_no,4,3) ||

'.' || SUBSTR(p_phone_no,7);

END format_phone;

Mark for Review

(1) Points

The phone number 800.555.1234 is printed to the screen.

The phone number (800) 555-1234 is printed to the screen.


The phone number 800.555.1234 is placed into the p_phone_no variable. (*)

The procedure does not execute because the input variable is not properly declared.

8 Lesson 3.

11. Procedure NUMPROC has been created as:

CREATE PROCEDURE numproc

(x NUMBER, y NUMBER := 100, z NUMBER) IS BEGIN ....

You want to call the procedure, passing arguments of 10 for X and 20 for Z. Which one of the following
calls is correct?

Mark for Review

(1) Points

numproc(10,,20);

numproc(x=10,z=20);
numproc(10,z=>20); (*)

numproc(x=>10,20);

8 Lesson 3.

1. A stored function: Mark for Review

(1) Points

must have at least one IN parameter.

cannot be called in a SQL statement.

must return one and only one value. (*)

is called as a standalone executable statement.

9 Lesson 1.
2. A PL/SQL function can have IN OUT parameters. True or False? Mark for
Review

(1) Points

True

False (*)

[Correct] Correct

3. CREATE FUNCTION get_sal (p_id employees.employee_id%TYPE)

RETURN number

IS

v_sal employees.salary%TYPE := 0;

BEGIN

SELECT salary INTO v_sal

FROM employees

WHERE employee_id = p_id;

RETURN v_sal;

END get_sal;

Which variable is passed to the function and which variable is returned from the function?

Mark for Review


(1) Points

GET_SAL is passed and V_SAL is returned.

SALARY is passed and P_ID is returned.

EMPLOYEE_ID is passed and SALARY is returned.

P_ID is passed and V_SAL is returned. (*)

9 Lesson 1.

4. You have created a function called GET_COUNTRY_NAME which accepts a


country_id as an IN parameter and returns the name of the country. Which one of the following calls to
the function will NOT work? Mark for Review

(1) Points

v_name := get_country_name(100);

DBMS_OUTPUT.PUT_LINE(get_country_name(100));
SELECT get_country_name(100) FROM dual;

BEGIN get_country_name(100, v_name); END; (*)

[Correct] Correct

5. The following function has been created:

CREATE OR REPLACE FUNCTION find_sal

(p_emp_id IN employees.employee_id%TYPE)

RETURN NUMBER IS ...

We want to invoke this function from the following anonymous block:

DECLARE

v_mynum NUMBER(6,2);

v_mydate DATE;

BEGIN

... Line A

END;

Which of the following would you include at Line A?

Mark for Review


(1) Points

find_sal(100,v_mynum);

v_mynum := find_sal(100); (*)

v_mydate := find_sal(100);

find_sal(v_mynum,100);

9 Lesson 1.

6. Function GET_JOB accepts an employee id as input and returns that employee's


job id. Which of the following calls to the function will NOT work? Mark for Review

(1) Points

DBMS_OUTPUT.PUT_LINE(get_job(100));

IF get_job(100) = 'IT_PROG' THEN ...


get_job(100,v_job_id); (*)

v_job_id := get_job(100);

9 Lesson 1.

7. Function MYFUNC1 has been created, but has failed to compile because it
contains syntax errors. We now try to create procedure MYPROC1 which invokes this function. Which of
the following statements is true? Mark for Review

(1) Points

MYPROC1 will compile correctly, but will fail when it is executed.

MYPROC1 will compile and execute succesfully.

MYPROC1 will fail to compile because the function is invalid. (*)

MYPROC1 will compile and execute successfully, except that the call to MYFUNC1 will be treated
as a comment and ignored.
9 Lesson 1.

8. Which of the following is found in a function and not a procedure? Mark


for Review

(1) Points

An exception section

IN parameters

Local variables in the IS/AS section

Return statement in the header (*)

[Correct] Correct

9. Procedure p1 has a single OUT parameter of type DATE. Function f1 returns a


DATE. What is the difference between p1 and f1? Mark for Review

(1) Points
p1 can be invoked from an anonymous block but f1 cannot.

f1 can be used within a SQL statement but p1 cannot. (*)

p1 can have as many IN parameters as needed but f1 cannot have more than two IN
parameters.

There is no difference because they both return a single value of the same datatype.

9 Lesson 1.

10. What is wrong with the following code?

CREATE FUNCTION annual_comp

(sal employees.salary%TYPE,

comm_pct IN employees.commission%TYPE)

RETURN NUMBER(5,2)

IS

BEGIN

RETURN (sal*12) + NVL(comm_pct,0)*12*sal;

END annual_comp;

Mark for Review


(1) Points

The sal parameter should specify the IN keyword.

The RETURN NUMBER has a scale and precision. (*)

There should be parentheses () around the expression: NVL(comm_pct,0)*12*sal

The END; statement should not include the function name.

9 Lesson 1.

11. Based on the following function definition:

Create function annual_comp

(sal employees.salary%type,

comm_pct In employees.commission%type)

...

Which one of the following is an incorrect call for annual_comp?

Mark for Review

(1) Points
Execute dbms_output.put_line(annual_comp (1000,.2));

Select employee_id, annual_comp(salary, commission_pct)

from employees;

Declare

Ann_comp number (6,2);

Begin

...

Ann_comp := annual_comp(1000,.2);

...

End;

Select employee_id, annual_comp(salary)

from employees; (*)

9 Lesson 1.

12. To create a function successfully, the following steps should be performed.

A Re-execute the code until it compiles correctly


B Write the code containing the CREATE or REPLACE FUNCTION followed by the function code

C Test the function from a SQL statement or an anonymous block

D If the function fails to compile, correct the errors

E Load the code into Application Express

F Execute the code in Application Express

What is the correct order to perform these steps?

Mark for Review

(1) Points

B,E,F,D,A,C (*)

D,B,E,F,A,C

B,C,E,F,D,A

A,B,E,F,D,C

[Correct] Correct
13. When using Invoker's rights, the invoker needs privileges on the database
objects referenced within the subprogram, as well as GRANT privilege on the procedure. True or False?
Mark for Review

(1) Points

True

False (*)

[Correct] Correct

14. What will happen when the following subprogram is compiled?

PROCEDURE at_proc IS

PRAGMA AUTONOMOUS_TRANSACTION;

dept_id NUMBER := 90;

BEGIN

UPDATE

INSERT

END at_proc;

Mark for Review

(1) Points
The subprogram will work without errors

The subprogram will fail because of an error in the SELECT statement. (*)

The subprogram will fail because the RETURN is not specified.

The program will compile successfully.

9 Lesson 6.

15. A function may execute more than one RETURN statement found in the body of
that function. True or False? Mark for Review

(1) Points

True

False (*)

9 Lesson 6.
1. Which of the following is NOT a benefit of user-defined functions? Mark for Review

(1) Points

They can add business rules to the database and can be reused many times.

They can be used in a WHERE clause to filter data.

They can do the same job as built-in system functions such as UPPER and ROUND. (*)

They can often be used inside SQL statements.

9 Lesson 2.

2. User-defined functions can extend the power of SQL statements where Oracle
does not provide ready-made functions such as UPPER and LOWER. True or False? Mark for
Review

(1) Points

True (*)
False

[Correct] Correct

3. Which of the following is NOT a legal location for a function call in a SQL
statement? Mark for Review

(1) Points

FROM clause of a SELECT statement (*)

WHERE clause in a DELETE statement

SET clause of an UPDATE statement

VALUES clause of an INSERT statement

[Correct] Correct
4. The following function has been created:

CREATE OR REPLACE FUNCTION upd_dept

(p_dept_id IN departments.department_id%TYPE)

RETURN NUMBER IS

BEGIN

UPDATE departments SET department_name = 'Accounting'

WHERE department_id = p_dept_id;

RETURN p_dept_id;

END;

Which of the following will execute successfully?

Mark for Review

(1) Points

DELETE FROM departments

WHERE department_id = upd_dept(department_id);

SELECT upd_dept(department_id)

FROM employees;

DELETE FROM employees

WHERE department_id = upd_dept(80);


(*)

SELECT upd_dept(80)

FROM dual;

[Correct] Correct

5. You want to create a function which can be used in a SQL statement. Which one
of the following can be coded within your function? Mark for Review

(1) Points

RETURN BOOLEAN

Onqters (*)

An OUT parameter

COMMIT;
9 Lesson 2.

6. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE


FUNCTION double_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER IS BEGIN
RETURN(p_salary * 2); END; Which of the following calls to DOUBLE_SAL will NOT work? Mark
for Review

(1) Points

SELECT * FROM employees WHERE double_sal(salary) > 20000;

SELECT * FROM employees ORDER BY double_sal(salary) DESC;

UPDATE employees SET salary = double_sal(salary);

SELECT last_name, double_sal(salary) FROM employees;

None of the above; they will all work (*)

9 Lesson 2.
1. Which of the following best describes the Data Dictionary? Mark for Review

(1) Points

It is a set of tables which can be updated by any user who has the necessary privileges.

It is an automatically managed master catalog of all the objects stored in the database. (*)

It contains a backup copy of all the data in the database.

It contains a list of all database tables which are not in any schema.

[Correct] Correct

2. Which of the following is NOT a benefit of the Data Dictionary? Mark for
Review

(1) Points

It allows us to remind ourselves of the names of our tables, in case we have fogotten them.
It allows us to check which system privileges have been granted to us.

It will speed up the execution of SELECT statements in which the WHERE clause column is not
indexed. (*)

It allows the PL/SQL compiler to check for object existence; for example, when creating a
procedure which references a table, the PL/SQL compiler can check that the table exists.

9 Lesson 3.

3. User BOB is not a database administrator. BOB wants to see the names of all the
tables in his schema, as well as all the tables in other users' schemas which he has privileges to use.
Which Data Dictionary view would BOB query to do this? Mark for Review

(1) Points

USER_TABLES

ALL_TABLES (*)

DBA_TABLES
USER_TAB_COLUMNS

None of the above

9 Lesson 3.

4. User MARY executes this SQL statement:

SELECT COUNT(*) FROM USER_VIEWS;

A value of 15 is returned. Which of the following statements is true?

Mark for Review

(1) Points

There are 15 views in Mary's schema. (*)

Mary has created views on 15 of her tables.

There are 15 views in the database.

Other users have granted Mary SELECT privilege on 15 of their views.


9 Lesson 3.

5. A user executes the following statement:

CREATE INDEX fn_index ON employees(first_name);

What output will the following statement now display:

SELECT index_name

FROM user_indexes

WHERE index_name LIKE 'fn%';

Mark for Review

(1) Points

fn_index

FN_INDEX

fn_index FN_INDEX

No output will be displayed (*)


9 Lesson 3.

6. Which of the following will display how many objects of each type are in a user's
schema? Mark for Review

(1) Points

SELECT COUNT(*)

FROM user_objects;

SELECT object_type, COUNT(*)

FROM user_objects

GROUP BY object_type;

(*)

SELECT object_type, COUNT(*)

FROM all_objects

GROUP BY object_type;
DESCRIBE user_objects

GROUP BY object_type;

9 Lesson 3.

7. Which of the following statements about the "super-view" DICTIONARY is true?


Mark for Review

(1) Points

It lists all the dictionary views.

It can be thought of as a "catalog of the master catalog".

We can use it like a Web search engine to remind ourselves of the names of dictionary views.

All of the above (*)

None of the above


9 Lesson 3.

8. You have forgotten the name of the Dictionary view USER_TABLES. Which of the
following statements is the best and quickest way to remind yourself? Mark for Review

(1) Points

SELECT * FROM dictionary

WHERE table_name = 'USER%';

Read the online Oracle documentation at http://technet.oracle.com.

SELECT * FROM dict

WHERE table_name LIKE 'USER%TAB%';

(*)

SELECT * FROM dictionary

WHERE table_name = 'USER_TABLES';


Phone the database administrator.

[Correct] Correct

1. proc_a has been created as follows:

CREATE OR REPLACE PROCEDURE proc_a IS

v_last_name employees.last_name%TYPE;

BEGIN

SELECT last_name INTO v_last_name FROM employees

WHERE employee_id = 999;

/* This SELECT will raise an exception because employee_id 999 does not exist */

DBMS_OUTPUT.PUT_LINE('This SELECT failed');

END;

proc_b is now created as follows:

CREATE OR REPLACE PROCEDURE proc_b IS

BEGIN

proc_a;

DBMS_OUTPUT.PUT_LINE('proc_a was invoked');

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An exception occurred');

END;
What will be displayed when proc_b is executed?

Mark for Review

(1) Points

An exception occurred

(*)

This SELECT failed

proc_a was invoked

An exception occurred

This SELECT failed

This SELECT failed

proc_a was invoked

Nothing will be displayed


[Correct] Correct

2. Procedure ins_emp accepts an employee_id as an IN parameter and attempts to


insert a row with that employee_id into the EMPLOYEES table. Ins_emp does not contain an exception
section. A second procedure is created as follows:

CREATE OR REPLACE PROCEDURE call_ins_emp IS

BEGIN

ins_emp(99); -- this employee does not exist

ins_emp(100); -- this employee already exists

ins_emp(999); -- this employee does not exist

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('An exception occurred');

END;

When call_ins_emp is executed, assuming AutoCommit is turned on, which rows will be inserted into
the EMPLOYEES table?

Mark for Review

(1) Points

99 only (*)

99 and 999
All three rows will be inserted

999 only

No rows will be inserted

9 Lesson 4.

3. The database administrator has granted the DROP ANY PROCEDURE privilege to
user KIM. This allows Kim to remove other users' procedures and functions from the database. How
would Kim now drop function GET_EMP, which is owned by user MEHMET? Mark for Review

(1) Points

DROP FUNCTION get_emp FROM mehmet

DROP FUNCTION mehmet.get_emp (*)

DROP PROCEDURE mehmet.get_emp

DROP PROGRAM mehmet.get_emp


None of the above

9 Lesson 4.

4. You need to remove procedure BADPROC from your schema. What is the
correct syntax to do this? Mark for Review

(1) Points

DELETE PROCEDURE badproc;

DROP PROGRAM badproc;

ALTER PROCEDURE badproc DISABLE;

DROP PROCEDURE badproc; (*)

9 Lesson 4.
5. Which view would you query to see the detailed code of a procedure? Mark
for Review

(1) Points

user_source (*)

user_procedures

user_objects

user_dependencies

user_errors

9 Lesson 4.

6. Which dictionary view will list all the PL/SQL subprograms in your schema?
Mark for Review

(1) Points
user_source

user_procedures

user_objects (*)

1. Procedure GET_EMPS includes a SELECTFROM EMPLOYEES. The procedure was created using
Invoker's Rights. Which of the following statements are true? (Choose three.) Mark for Review

(1) Points

(Choose all correct answers)

The user who executes the procedure needs EXECUTE privilege on the procedure. (*)

The creator of the procedure needs SELECT privilege on EMPLOYEES. (*)

The user who executes the procedure does not need any privileges.

The user who executes the procedure needs SELECT privilege on EMPLOYEES. (*)
9 Lesson 6.

2. Which of the following is the correct syntax to create a procedure using


Invoker's Rights? Mark for Review

(1) Points

CREATE PROCEDURE myproc IS

AUTHID CURRENT_USER

BEGIN ...

CREATE PROCEDURE myproc

AUTHID CURRENT_USER IS

BEGIN ...

(*)

CREATE PROCEDURE AUTHID CURRENT_USER myproc IS

BEGIN ...

CREATE PROCEDURE myproc IS

BEGIN
AUTHID CURRENT_USER ...

[Correct] Correct

3. User SALLY's schema contains a NEWEMP table. Sally uses Invoker's rights to
create procedure GET_NEWEMP which includes the line:

SELECT ... FROM NEWEMP ... ;

Sally also grants EXECUTE privilege on the procedure to CURLY, but no other privileges. What will
happen when Curly executes the procedure?

Mark for Review

(1) Points

The procedure will execute successfully.

The procedure will fail because Curly does not have SELECT privilege on NEWEMP.

The procedure will fail because there is no NEWEMP table in Curly's schema. (*)

The procedure will fail because Curly does not have the EXECUTE ANY PROCEDURE system
privilege.
9 Lesson 6.

4. Users SYS (the DBA), TOM, DICK, and HARRY each have an EMPLOYEES table in
their schemas. SYS creates a procedure DICK.SEL_EMP using Invoker's Rights which contains the
following code:

SELECT ... FROM EMPLOYEES ... ;

HARRY now executes the procedure. Which employees table will be queried?

Mark for Review

(1) Points

SYS.EMPLOYEES

DICK.EMPLOYEES

HARRY.EMPLOYEES (*)

None of the above


9 Lesson 6.

5. When using Invoker's rights, the invoker needs privileges on the database
objects referenced within the subprogram, as well as GRANT privilege on the procedure. True or False?
Mark for Review

(1) Points

True

False (*)

[Correct] Correct

6. Which statement is true regarding the following subprogram?

PROCEDURE at_proc IS

PRAGMA AUTONOMOUS_TRANSACTION;

dept_id NUMBER := 90;

BEGIN

UPDATE ...

INSERT ...
COMMIT;

END at_proc;

Mark for Review

(1) Points

The subprogram's success depends on the calling program.

The subprogram will fail because the RETURN is not specified.

The subprogram's success is independent of the calling program. (*)

The subprogram cannot do a COMMIT.

9 Lesson 6.

7. An autonomous transaction subprogram may be in a the same package as the


calling subprogram or may be in a separate subprogram. True or False? Mark for Review

(1) Points

True
False (*)

9 Lesson 6.

1. User SVETLANA creates a view called EMP_VIEW that is based on a SELECT from her EMPLOYEES
table. Svetlana now wants user PHIL to be able to query the view. What is the smallest set of object
privileges that Svetlana must grant to Phil? Mark for Review

(1) Points

SELECT on EMP_VIEW and SELECT on EMPLOYEES

SELECT and EXECUTE on EMP_VIEW

SELECT on EMP_VIEW (*)

SELECT on EMP_VIEW and REFERENCES on EMPLOYEES

[Correct] Correct
2. User COLLEEN owns an EMPLOYEES table and wants to allow user AYSE to
create indexes on the table. Which object privilege must Colleen grant to Ayse? Mark for Review

(1) Points

SELECT on EMPLOYEES

INDEX on EMPLOYEES (*)

ALTER on EMPLOYEES

CREATE on EMPLOYEES

None of the above

9 Lesson 5.

3. User FRED creates a procedure called DEL_DEPT using Definer's Rights, which
deletes a row from Fred's DEPARTMENTS table. What privilege(s) will user BOB need to be able to
execute Fred's procedure? Mark for Review

(1) Points
EXECUTE on DEL_DEPT (*)

EXECUTE on DEL_DEPT and DELETE on DEPARTMENTS

EXECUTE on DEL_DEPT and DELETE on FRED.DEPARTMENTS

DELETE on FRED.DEPARTMENTS

9 Lesson 5.

4. USERB creates a function called SEL_PROC (using Definer's Rights) which


includes the statement:

SELECT ... FROM usera.employees ...;

USERC needs to execute UserB's procedure. What privileges are needed for this to work correctly?
(Choose two.)

Mark for Review

(1) Points

(Choose all correct answers)


UserB needs SELECT on userA.employees (*)

UserC needs SELECT on userA.employees

UserC needs EXECUTE on userB.sel_proc (*)

UserA needs EXECUTE on userB.sel_proc

UserC needs EXECUTE on Userb

9 Lesson 5.

5. User DIANE owns a DEPARTMENTS table. User JOEL needs to update the
location_id column of Diane's table, but no other columns. Which SQL statement should Diane execute
to allow this? Mark for Review

(1) Points

GRANT UPDATE ON departments TO joel;


GRANT UPDATE ON departments(location_id) TO joel;

GRANT UPDATE ON departments.location_id TO joel;

GRANT UPDATE(location_id) ON departments TO joel; (*)

GRANT UPDATE ON location_id OF departments TO joel;

9 Lesson 5.

6. User TOM needs to grant both SELECT and INSERT privileges on both his
EMPLOYEES and DEPARTMENTS tables to both DICK and HARRY. What is the smallest number of GRANT
statements needed to do this? Mark for Review

(1) Points

2 (*)
3

[Correct] Correct

user_dependencies

user_subprograms

9 Lesson 4.

1. Which of the following can be included in a package? Mark for Review

(1) Points

procedures
variables

PL/SQL types

Exceptions

All of the above (*)

10 Lesson 1.

2. Which of the following are good reasons to group a set of procedures and
functions into a package? Mark for Review

(1) Points

Application developers do not need to know the details of the package body code.

Related subprograms and variables can be grouped together for easier management and
maintenance.
If the detailed code is changed, applications which invoke the package do not need to be
recompiled.

All of the above. (*)

[Correct] Correct

3. In which component of a package is the full definition of a public procedure


written? Mark for Review

(1) Points

Body (*)

Specification

Both the body and the specification

Neither the body nor the specification


10 Lesson 1.

4. The two parts of a package are stored as separate objects in the database. True
or False? Mark for Review

(1) Points

True (*)

False

10 Lesson 1.

5. To be able to invoke a package subprogram from outside the package, it must


be declared in the package: Mark for Review

(1) Points

Body

Specification
Body and the specification (*)

None of the above

[Correct] Correct

6. A number variable declared in a package is initialized to 0 unless assigned


another value. True or False? Mark for Review

(1) Points

True

False (*)

[Correct] Correct

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

Mark for Review

(1) Points

(Choose all correct answers)

BEGIN

dept_pack.ins_dept(20);

END;

(*)

BEGIN

dept_pack.get_dept(20);

END;

DECLARE

v_deptname VARCHAR2(20);

BEGIN

v_deptname := get_dept(50);

END;
CREATE PROCEDURE dept_proc IS

v_deptname VARCHAR2(20);

BEGIN

v_deptname := dept_pack.get_dept(40);

END;

(*)

BEGIN

dept_pack(30);

END;

10 Lesson 1.

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

DESCRIBE emp_pack

(*)

DESCRIBE emp_pack.del_emp

DESCRIBE emp_pack.show_emp

None of the above

10 Lesson 1.

1. A public component declared in the package specification can be referenced by


a private component defined in the package body. True or False? Mark for Review

(1) Points
True (*)

False

[Correct] Correct

2. A local variable declared within a procedure in a package can be referenced by


any other component of that package. True or False? Mark for Review

(1) Points

True

False (*)

10 Lesson 2.

3. Examine the following package specification:

CREATE OR REPLACE PACKAGE mypack IS


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

Mark for Review

(1) Points

(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 variable can be modified by:

BEGIN

mypack.percent_tax := 10;

END;

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

The procedure can be invoked by:

BEGIN

mypack.proc1;

END;

(*)

10 Lesson 2.

4. We want to remove both the specification and the body of package CO_PACK
from the database. Which of the following commands will do this? Mark for Review

(1) Points

DROP BOTH co_pack;

DROP PACKAGE BODY co_pack;


DROP PACKAGE co_pack; (*)

DROP PACKAGE SPECIFICATION co_pack;

None of the above

10 Lesson 2.

5. Which one of the following queries would you use to see the detailed code of a
package called EMP_PKG? Mark for Review

(1) Points

SELECT text FROM user_source WHERE name = 'EMP_PKG' AND type = 'PACKAGE' ORDER BY
line;

SELECT source FROM user_packages 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 BODY' ORDER
BY line; (*)

[Correct] Correct

6. 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

(0) Points

The names of all package specifications in the user's schema

The names of all package specifications and package bodies in the user's schema (*)

The parameters which must be used when invoking all packaged subprograms 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

[Correct] Correct

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

10 Lesson 2.

8. A local variable defined inside a package procedure is visible to the calling


environment. True or False? Mark for Review

(1) Points

True
False (*)

[Correct] Correct

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

(1) Points

True

False (*)

10 Lesson 2.

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

(0) Points
emp_pkg.emp_sal(101);

scott.emp_pkg.emp_sal(101): (*)

emp_sal(101);

None of the above

All of the above

[Correct] Correct

Section 1

(Answer all questions in this section)

1. 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; Mark for Review

(1) Points

1 and 2
1 and 4

2 and 4

2 and 3 (*)

3 and 4

10 Lesson 3.

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

Mark for Review


(1) Points

(Choose all correct answers)

over_pack.do_work1('Smith',20);

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(param1=>'Smith');

10 Lesson 3.

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

(1) Points
True (*)

False

10 Lesson 3.

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

10 Lesson 3.

5. Which one of the following is NOT a restriction on a package function called


from a SQL statement? Mark for Review

(1) Points
The function can include a COMMIT.

The function can be overloaded. (*)

The function can include a ROLLBACK.

The function can return a BOOLEAN.

10 Lesson 3.

6. The package name must be included when calling a package function from a
SELECT statement executed outside the package. True or False? Mark for Review

(1) Points

True (*)

False
[Correct] Correct

7. Package FORWARD_PACK contains two procedures: PROC1 is public while


PROC2 is private (not declared in the package specification). These procedures have no parameters.
Which of the following package bodies will NOT compile successfully? (Choose two.) Mark for
Review

(1) Points

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

10 Lesson 3.

8. Which of the following best describes a package initialization block? Mark


for Review
(1) Points

It is a named procedure in a package which must be invoked by a user before any other part of
the package can be invoked.

It is an anonymous block in the package specification.

It is an anonymous block at the end of a package body which executes automatically the first
time each user session invokes a subprogram in the package. (*)

It is a private function within the package body.

Because it is an anonymous block, it cannot be invoked and therefore will never execute. It is
treated as a set of comments.

10 Lesson 3.

9. A bodiless package contains what? Mark for Review

(1) Points

Procedures only
Functions only

Public variables only (*)

Private variables only

10 Lesson 3.

10. 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] Correct

11. How would you invoke the constant km_to_mile from the global_consts
bodiless package at VARIABLE A?

SELECT trail_name, distance_in_km * VARIABLE A

FROM trails

WHERE park_name = 'YOSEMITE';

Mark for Review

(1) Points

km_to_mile.global_consts

km_to_mile (global_consts)

global_consts.km_to_mile (*)

global_consts (km_to_mile)
10 Lesson 3.

12. When using a package function in DML statements, which rules must you
follow? (Choose three) Mark for Review

(1) Points

(Choose all correct answers)

Must not end the current transaction (*)

Can read or modify the table being changed by that DML statement

Changes to a package variable could have an impact on another stored function (*)

Cannot execute a DML statement or modify the database (*)

10 Lesson 3.
13. 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] Correct

14. INDEX BY is missing from the empt_tab TYPE declaration. What is the most
efficient declaration?
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;

Mark for Review

(1) Points

INDEX BY INTEGER

INDEX BY BINARY

INDEX BY BINARY_INTEGER (*)

INDEX ALL

10 Lesson 3.

You might also like