0% found this document useful (0 votes)
597 views19 pages

Final Exams em 1

This document describes how to store an entire record in a single variable in PL/SQL using %ROWTYPE or by creating a custom record structure as a type and declaring a variable of that type.

Uploaded by

Marius Iulian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
597 views19 pages

Final Exams em 1

This document describes how to store an entire record in a single variable in PL/SQL using %ROWTYPE or by creating a custom record structure as a type and declaring a variable of that type.

Uploaded by

Marius Iulian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

1.

You can store


a whole
record in a
single
variable using
%ROWTYPE
or by
creating yoru
own record
structure as a
type and
then
declaring a
variable of
that type.

Mark for Review


(1) Points

True (*)
False
Correct.
2. Identify the valid collection types:

Mark for Review


(1) Points

(Choose all correct answers)


INDEX BY TABLE (*)
INDEX BY VIEW
INDEX BY TABLE OF ROWS
INDEX BY TABLE OF RECORDS (*)
Incorrect. Refer to Section 6 Lesson 2.

Section 7
(Answer all questions in this section)
3. Examine the following code fragment. At Line A, you want to raise an
exception if the fetched salary value is greater than 30000. How can you
do this?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 100;
IF v_salary > 30000 THEN
-- Line A

Mark for Review


(1) Points

END IF;
...
Test for WHEN VALUE_TOO_HIGH in the exception section.
Use RAISE_APPLICATION_ERROR to raise an exception explicitly. (*)
Test for WHEN OTHERS in the exception section, because WHEN
OTHERS traps all exceptions.
Define an EXCEPTION variable and associate it with an Oracle Server
error number using PRAGMA EXCEPTION_INIT.
Correct
4. An attempt to update an employee's salary to a negative value will violate
a check constraint and raise an ORA-02290 exception. Which of the
following is a correct definition of a handler for this exception?

Mark for Review


(1) Points

DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(-02290,e_sal_excep);
DECLARE
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);
e_sal_excep EXCEPTION;
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,-02290);
(*)
DECLARE
e_sal_excep EXCEPTION;
PRAGMA_EXCEPTION_INIT(e_sal_exception,-02290);
DECLARE
e_sal_excep EXCEPTION;
PRAGMA EXCEPTION_INIT(e_sal_excep,02290);
Correct
5. An attempt to insert a null value into a NOT NULL table column raises an
ORA-01400 exception. How can you code an exception handler to trap this
exception?
Test for WHEN ORA-1400 in the exception section.
Declare a variable e_null_excep of type EXCEPTION, associate it with
ORA-01400 using a PRAGMA directive, and test for WHEN
e_null_excep in the exception section. (*)
Declare a variable e_null_excep of type VARCHAR2, associate it with
ORA-01400 using a PRAGMA directive, and test for WHEN
e_null_excep in the exception section.
Declare a variable as follows: e_null_excep EXCEPTION := -01400;
Then test for WHEN e_null_excep in the exception section.
Correct

Mark for Review


(1) Points

6. Which of the following are examples of predefined Oracle Server errors?


(Choose three.)

Mark for Review


(1) Points

(Choose all correct answers)


TOO_MANY_ROWS (*)
NO_DATA_FOUND (*)
OTHERS
ZERO_DIVIDE (*)
E_INSERT_EXCEP
Correct
7. The following exception handler will successfully insert the Oracle error
number and error message into a log table whenever an Oracle Server
error occurs. True or False?

Mark for Review


(1) Points

EXCEPTION
WHEN OTHERS THEN
INSERT INTO err_log_table (num_col, char_col)
VALUES (SQLCODE, SQLERRM);
END;
(Assume that err_log_table has been created with suitable columns and
datatypes.)
True
False (*)
Correct
8. Which of the following best describes a user-defined exception?

Mark for Review


(1) Points

A predefined Oracle Server error such as NO_DATA_FOUND


A non-predefined Oracle Server error such as ORA-01400
An error which is not automatically raised by the Oracle server (*)
Any error which has an Oracle error number of the form ORA-nnnnn
Correct
9. Using two nested blocks, a TOO_MANY_ROWS exception is raised within
the inner block. Which of the following exception handlers will successfully
handle the exception?

Mark for Review


(1) Points

WHEN TOO_MANY_ROWS in the inner block


WHEN TOO_MANY_ROWS in either block
WHEN OTHERS in either block
WHEN OTHERS in the inner block
All of the above (*)
Correct
10. What will be displayed when the following code is executed?
<<outer>>
DECLARE
v_myvar NUMBER;
BEGIN
v_myvar := 10;
DECLARE
v_myvar NUMBER := 200;
BEGIN
outer.v_myvar := 20;
v_myvar := v_myvar / 0; -- this raises a ZERO_DIVIDE error
outer.v_myvar := 30;
END;
v_myvar := 40;
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE(v_myvar);
END;
10
20 (*)
30
40
200
Correct
11. The following code does not violate any
constraints and will not raise an ORA02292 error. What will happen when the
code is executed?
BEGIN
DECLARE
e_constraint_violation EXCEPTION;
PRAGMA
EXCEPTION_INIT(e_constraint_violation,
-2292);
BEGIN
DBMS_OUTPUT.PUT_LINE('Inner
block message');

Mark for Review


(1) Points

Mark for Review


(1) Points

END;
EXCEPTION
WHEN e_constraint_violation THEN
DBMS_OUTPUT.PUT_LINE('Outer
block message');
END;
'Inner block message' will be displayed.
The code will fail because the exception is
declared in the inner block but is
referenced in the outer block. (*)
'Outer block message' will be displayed.
The code will fail because line 4 should
read: PRAGMA EXCEPTION_INIT(-2292,
e_constraint_violation);
Correct
12. What will happen when the following code is
executed?

Mark for Review


(1) Points

DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
RAISE e_excep2; END;
END;
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. (*)
Correct
13. While a PL/SQL block is executing, more than
one exception can occur at the same time. True
or False?
True
False (*)

Mark for Review


(1) Points

Correct
14. Which of the following is NOT an advantage of
including an exception handler in a PL/SQL
block?

Mark for Review


(1) Points

Protects the database from errors


Code is more readable because errorhandling routines can be written in the
same block in which the error occurred
Prevents errors from occurring (*)
Avoids costly and time-consuming
correction of mistakes
Correct
15. Which of the following are good practice
guidelines for exception handling? (Choose
three.)

Mark for Review


(1) Points

(Choose all correct answers)


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. (*)
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. (*)
Correct
16. Which of the following best describes a PL/SQL
exception?

Mark for Review


(1) Points

A user enters an invalid password while


trying to log on to the database.
An error occurs during execution which
disrupts the normal operation of the
program. (*)
A DML statement does not modify any
rows.
The programmer makes a spelling mistake
while writiing the PL/SQL code.
Correct

17. No employees are in department 99. What


message or messages will be displayed when
the following code is executed?

Mark for Review


(1) Points

DECLARE
e_my_excep EXCEPTION;
BEGIN
BEGIN
UPDATE employees SET salary = 10000
WHERE department_id = 99;
IF SQL%ROWCOUNT = 0 THEN
RAISE e_my_excep;
END IF;
EXCEPTION
WHEN e_my_excep THEN
DBMS_OUTPUT.PUT_LINE('Message 1');
RAISE e_my_excep;
DBMS_OUTPUT.PUT_LINE('Message 2');
END;
DBMS_OUTPUT.PUT_LINE('Message 3');
EXCEPTION
WHEN e_my_excep THEN
DBMS_OUTPUT.PUT_LINE('Message 4');
END;
Message
Message
Message
Message
Message
Message
Message
Message
Message

1
3
1
2
1
3
4
1
4

(*)
Correct
18. A user-defined exception is raised by using:

Mark for Review


(1) Points

FLAG exception_name;
RAISE exception-name; (*)
PRAGMA EXCEPTION_INIT
RAISE(error_number, exception_name);
Incorrect. Refer to
Section 7 Lesson 3.

19. A user-defined exception can be raised:


A. In the declaration section
B. In the executable section
C. In the exception section

Mark for Review


(1) Points

B
C
A and B
B and C (*)
A and C
Incorrect. Refer to
Section 7 Lesson 3.
20. Which of the following will successfully return a
user-defined error message?

Mark for Review


(1) Points

RAISE_APPLICATION_ERROR('Error
Raised',-22001);
RAISE_APPLICATION_ERROR(20257,'Error raised'); (*)
RAISE_APPLICATION_ERROR(22001,'Error Raised');
RAISE_APPLICATION_ERROR('Error
Raised',-20257);
Correct
21. Suppose
you set up
a
parameter
with an
explicit
OUT mode.
What is
true about
that
parameter?

Mark for Review


(1) Points

It must have a DEFAULT value.


It cannot have a DEFAULT value. (*)
It acts like a constant (its value cannot be changed inside the
subprogram).
It must be the same type as the matching IN parameter.
It inherits its type from the matching IN parameter.
Correct

22. The following procedure has been created:


CREATE OR REPLACE PROCEDURE myproc
(A IN NUMBER := 20,
B IN NUMBER,
C IN NUMBER DEFAULT 30)
IS .....
Which of the following will invoke the procedure correctly?

Mark for Review


(1) Points

myproc(40);
myproc(10, B => 30, 50);
myproc(C => 25);
All of the above
None of the above (*)
Correct
23. Procedure SOMEPROC has five parameters named A, B, C, D, E in that order.
The procedure was called as follows:

Mark for Review


(1) Points

SOMEPROC(10,20,D=>50);
How was parameter D referenced?
Positionally
Named (*)
A combination of positionally and named
A combination of named and defaulted
Defaulted
Correct
24. Suppose you set up a parameter with an explicit IN mode. What is true about
that parameter?

Mark for Review


(1) Points

It must have a DEFAULT value.


It cannot have a DEFAULT value.
It acts like a constant (its value cannot be changed inside the
subprogram). (*)
It must be the same type as the matching OUT parameter.
It inherits its type from the matching OUT parameter.
Incorrect. Refer to Section 8 Lesson 3.

25. A procedure will execute faster if it has at least one parameter.

Mark for Review


(1) Points

True
False (*)
Correct
26. You want to create a procedure named SOMEPROC which accepts a single
parameter named SOMEPARM. The parameter can be up to 100 characters
long. Which of the following is correct syntax to do this?

Mark for Review


(1) Points

CREATE PROCEDURE someproc


(someparm varchar2)
IS
BEGIN ...
(*)
CREATE PROCEDURE someproc
(someparm varchar2(100) )
IS
BEGIN...
CREATE PROCEDURE someproc
IS
(someparm VARCHAR2;)
BEGIN...
CREATE PROCEDURE someproc
someparm varchar2(100);
IS
BEGIN...
CREATE PROCEDURE someproc
(someparm 100)
IS
BEGIN ...
Correct
27. You have created a procedure named MYPROC that accepts three IN
parameters A, B, and C (all numbers). Which of the following calls to MYPROC
is NOT correct?
myproc(5,10,20);
myproc(a=>5,b=>10,20) (*)
myproc(a=>5,b=>10,c=>20)
myproc(5,10,c=>20)
Correct

Mark for Review


(1) Points

28. Which of the following best describes how an IN parameter affects a


procedure?

Mark for Review


(1) Points

It describes the order in which the procedure's statements should be


executed.
It describes which parts of the procedure's code are optional or
conditional.
It makes the procedure execute faster.
It passes a value into the procedure when the procedure is invoked. (*)
It allows complex calculations to be executed inside the procedure.
Correct
29. Which of the following is NOT correct coding for a procedure parameter?

Mark for Review


(1) Points

(p_param IN VARCHAR2)
(p_param VARCHAR2)
(p_param VARCHAR2(50)) (*)
(p_param employees.last_name%TYPE)
(p_param IN OUT VARCHAR2)
Correct
30. Which of the following keywords MUST be included in every PL/SQL procedure
definition? (Choose three.)

Mark for Review


(1) Points

(Choose all correct answers)


REPLACE
BEGIN (*)
IS or AS (*)
DECLARE
END (*)
Incorrect. Refer to Section 8 Lesson 1.
31. Which of the
following are
characteristics
of PL/SQL
subprograms
but not of
anonymous

Mark for Review


(1) Points

PL/SQL
blocks?
(Choose
three.)
(Choose all correct answers)
Can take parameters (*)
Are stored in the database (*)
Can begin with the keyword DECLARE
Are named (*)
Are compiled every time they are executed
Correct
32. A programmer creates a PL/SQL subprogram which is compiled and stored
in the database. Two separate users then execute an application which
invokes this subprogram four times. How many times must the subprogram
be recompiled?

Mark for Review


(1) Points

Two times
Four times
Zero times (*)
Eight times
One time
Correct
33. 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 to write
Better data security (*)
Easier code maintenance (*)
Faster performance (*)
Do not need to declare variables
Correct

34. The following are the steps involved in creating, and later modifying and
re-creating, a PL/SQL procedure in Application Express. In what sequence
should these steps be performed?

A.
B.
C.
D.
E.
F.

Mark for Review


(1) Points

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


Execute the code to create the procedure
Execute the code to re-create the procedure
Click on the "Save" button and save the procedure code
Modify the code in the SQL Commands window
Type the procedure code in the SQL Commands window

F,C,A,B,E,D
F,B,D,A,E,C (*)
E,D,F,C,A,B
F,B,D,E,A,C
F,B,C,D,E,A
Correct
35. A PL/SQL procedure named MYPROC has already been created and stored
in the database. Which of the following will successfully re-create the
procedure after some changes have been made to the code?

Mark for Review


(1) Points

CREATE PROCEDURE myproc IS ...


CREATE OR REPLACE PROCEDURE myproc IS .... (*)
UPDATE PROCEDURE myproc IS ...
ALTER PROCEDURE myproc IS ...
None of the above, because the procedure must be dropped before it
can be re-created.
Correct

Section 9
(Answer all questions in this section)
36. User REYHAN creates the following procedure:
CREATE PROCEDURE proc1
AUTHID CURRENT_USER IS
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count

Mark for Review


(1) Points

FROM tom.employees;
END;
User BILL wants to execute this procedure. What privileges will BILL need?
EXECUTE on REYHAN.PROC1 and SELECT on TOM.EMPLOYEES (*)
EXECUTE on REYHAN.PROC1
SELECT on TOM.EMPLOYEES
BILL needs no privileges
None of the above. The procedure will fail to compile because
REYHAN does not have SELECT privilege on TOM.EMPLOYEES.
Correct
37. How do you specify that you want a procedure MYPROCA to use Invoker's
Rights?

Mark for Review


(1) Points

CREATE OR REPLACE PROCEDURE myproca


AUTHID CURRENT_USER IS...
(*)
Invoker's Rights are the default, therefore no extra code is needed.
GRANT INVOKER TO myprocA;
ALTER PROCEDURE myproca TO INVOKER;
CREATE OR REPLACE PROCEDURE myproca
AUTHID OWNER IS...
Correct
38. How do you specify that you want a procedure MYPROCA to use "Definer's
Rights"?

Mark for Review


(1) Points

CREATE OR REPLACE PROCEDURE myproca


AUTHID CURRENT_USER IS...
CREATE OR REPLACE PROCEDURE myproca
AUTHID OWNER IS...
GRANT DEFINER TO myprocA;
ALTER PROCEDURE myproca TO DEFINER;
Definer's Rights are the default, therefore no extra code or commands
are needed. (*)
Correct
39. The function avg_ann_sal returns the average annual salary for a particular
department. The example below is a valid use of this function. True or
False?

Mark for Review


(1) Points

SELECT first_name, last_name


FROM employees
WHERE avg_ann_sal(20) > 15000;
True (*)
False
Correct
40. When creating a user-defined function, the size of the returned values may
be up to the size of any PL/SQL data type. True or False?

Mark for Review


(1) Points

True
False (*)
Correct
41. Which of
the
following
is a legal
location
for a
function
call in a
SQL
statement?
(Choose 3)

Mark for Review


(1) Points

(Choose all correct answers)


CREATE TABLE statement
WHERE clause in a DELETE statement (*)
The ORDER BY and GROUP BY clauses of a query (*)
VALUES clause of an INSERT statement (*)
Correct
42. Examine the following code (the code of CHILD2 is not shown):
CREATE PROCEDURE child1
IS v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 9999;
EXCEPTION

Mark for Review


(1) Points

WHEN NO_DATA_FOUND THEN NULL;


END child1;
CREATE PROCEDURE parent
IS BEGIN
child1;
child2;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END parent;
Employee_id 9999 does not exist. What happens when PARENT is executed?
CHILD1 handles the exception successfully and ends. PARENT continues
to execute and invokes CHILD2. (*)
CHILD1 ends abruptly, and PARENT handles the exception successfully
and ends. CHILD2 does not execute.
CHILD1 ends abruptly, and then PARENT also ends abruptly with an
unhandled exception.
PARENT handles the exception, and then CHILD1 resumes execution.
PARENT fails to compile because you cannot have the same exception
handler in two separate subprograms.
Correct
43. You want to remove the procedure NO_NEED from your schema. You
execute:
DROP PROCEDURE no_need;

Mark for Review


(1) Points

Which Data Dictionary views are updated automatically?


USER_PROCEDURES
USER_OBJECTS
USER_SOURCE
All of the above (*)
None of the above
Correct
44. You want to see the names, modes, and data types of the formal parameters
of function MY_FUNC in your schema. How can you do this? (Choose two)

Mark for Review


(1) Points

(Choose all correct answers)


Query USER_PARAMETERS
Query USER_SOURCE (*)
Query USER_FUNCTIONS

SHOW PARAMETER my_func;


DESCRIBE my_func; (*)
Incorrect. Refer to Section 9 Lesson 4.
45. What is wrong with the following code?
CREATE FUNCTION badfunc
(p_param NUMBER(4))
RETURN BOOLEAN
IS BEGIN
RETURN (p_param > 10);
END badfunc;

Mark for Review


(1) Points

P_PARAM must be declared AFTER the RETURN clause.


P_PARAM must have a default value.
The datatype of the IN parameter cannot have a precision or scale. It
must be NUMBER, not NUMBER(4). (*)
RETURN (p_param > 10); is wrong because you cannot return an
expression.
The NUMBER datatype must have a scale as well as a precision.
Correct
46. Which of the following is a difference between a procedure and a function?

Mark for Review


(1) Points

A procedure can include DML statements, but a function cannot.


A function must have at least one IN parameter, while parameters are
optional for a procedure.
A procedure can return a BOOLEAN datatype, while a function cannot.
A function can be used inside a SQL statement, while a procedure
cannot. (*)
A procedure can include an EXCEPTION section, while a function cannot.
Correct
47. Which of the following best describes a stored function?

Mark for Review


(1) Points

A subprogram that must return exactly one value (*)


A subprogram that must have at least one IN parameter
A subprogram that has no OUT or IN OUT parameters
A subprogram that executes automatically when a DML statement is
executed on a table

A subprogram which invokes another subprogram


Correct
48. Consider the following function:
CREATE FUNCTION ADD_EM
(a NUMBER := 1,
b NUMBER := 2 )
RETURN NUMBER
IS BEGIN
RETURN (a+b);
END ADD_EM;

Mark for Review


(1) Points

Which one of the following blocks will NOT work correctly?


DECLARE
x NUMBER;
BEGIN
x:= add_em(b=4);
END;
(*)
DECLARE
x NUMBER;
BEGIN
x:= add_em(4);
END;
DECLARE
x NUMBER;
BEGIN
x:= add_em(4,5);
END;
DECLARE
x NUMBER;
BEGIN
x:= add_em;
END;
None of them will work.
Correct
49. You have created a function named NEWFUNC. You now change some of the
function code, and try to recreate the function by executing:

Mark for Review


(1) Points

CREATE OR REPLACE FUNCTION newfunc .... ;


What happens?
The command fails because the function already exists.
The function is automatically dropped and then recreated. (*)
The command fails because you should execute: CREATE AND REPLACE
....;

A second function named NEWFUNC_2 is created.


The function is dropped but not recreated.
Correct
50. Which of the following is a difference between a procedure and a function?

Mark for Review


(1) Points

Functions cannot be nested; procedures can be nested to at least 8


levels.
A procedure can have default values for parameters, while a function
cannot.
An explicit cursor can be declared in a procedure, but not in a function.
A function cannot be used within a SQL statement; a procedure can be
used within SQL.
A function must return a value; a procedure may or may not. (*)
Correct

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy