0% found this document useful (0 votes)
289 views

Semester 1 Final Exam Oracle PL SQL 3

1. When a function already exists and you try to recreate it using CREATE OR REPLACE FUNCTION, the existing function is automatically dropped and then recreated. 2. The correct way to invoke a function within a PL/SQL block is to assign the function's return value to a variable, such as v_var1 := myfunc('Crocodile'). 3. The block that will not work correctly is the one that tries to invoke the function ADD_EM by passing the parameter b=4, since this function expects two separate parameters for a and b, not a single parameter.

Uploaded by

Game GM
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)
289 views

Semester 1 Final Exam Oracle PL SQL 3

1. When a function already exists and you try to recreate it using CREATE OR REPLACE FUNCTION, the existing function is automatically dropped and then recreated. 2. The correct way to invoke a function within a PL/SQL block is to assign the function's return value to a variable, such as v_var1 := myfunc('Crocodile'). 3. The block that will not work correctly is the one that tries to invoke the function ADD_EM by passing the parameter b=4, since this function expects two separate parameters for a and b, not a single parameter.

Uploaded by

Game GM
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/ 24

Test: Semester 1 Final Exam

1. You have created a function named NEWFUNC. You now change some of the f
unction code, and try to recreate the function by executing:
CREATE OR REPLACE FUNCTION newfunc .... ;
What happens?
Mark for Review
(1) Points

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

2. A function named MYFUNC has been created. This function


accepts one IN parameter of datatype VARCHAR2 and returns a NUMBER. You want to
invoke the function within the following anonymous block:
DECLARE
v_var1 NUMBER(6,2);
BEGIN
-- Line A
END;
What could be coded at Liine A?
Mark for Review
(1) Points

myfunc('Crocodile') := v_var1;

myfunc(v_var1) := 'Crocodile';

myfunc(v_var1, 'Crocodile');

v_var1 := myfunc('Crocodile'); (*)

myfunc('Crocodile', v_var1);
Correct

3. Consider the following function:


CREATE FUNCTION ADD_EM
(a NUMBER := 1,
b NUMBER := 2 )
RETURN NUMBER
IS BEGIN
RETURN (a+b);
END ADD_EM;
Which one of the following blocks will NOT work correctly?
Mark for Review
(1) Points

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

4. You try to create a function named MYFUNC. The function


does not compile correctly because there are errors in your code. Which Diction
ary view can you query to see the errors? Mark for Review
(1) Points
USER_SOURCE

USER_ERRORS (*)

USER_OBJECTS

USER_DEPENDENCIES

USER_COMPILES

Correct

5. Which of the following is a difference between a proced


ure 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 opt
ional 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.

Incorrect. Refer to Section 9 Lesson 1.

6. 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 execute
d on a table.

A subprogram which invokes another subprogram.

Correct

7. Which of the following is a benefit of user-defined fun


ctions? (Choose 3) Mark for Review
(1) Points
(Choose all correct answers)

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 and thereby increase e
fficiency. (*)

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

They can often be used inside SQL statements. (*)

Correct

8. Why will the following statement fail?


SELECT employee_id, tax(p_value => salary)
FROM employees;
Mark for Review
(1) Points

User-defined functions are not allowed in the SELECT clause

Name notation is not allowed (*)

The data type for the tax variable does not match the data type for sala
ry

The statement will execute and not fail


Correct

9. The function avg_ann_sal returns the average annual sal


ary for a particular department. The example below is a valid use of of this fun
ction. True or False?
SELECT first_name, last_name
FROM employees
WHERE avg_ann_sal(20) > 15000;
Mark for Review
(1) Points

True (*)

False

Correct

10. Which Data Dictionary view can be used to display the d


etailed code of a procedure in your schema? Mark for Review
(1) Points

USER_PROCEDURES

USER_OBJECTS

USER_SOURCE (*)

USER_SUBPROGRAMS

None of the above.

Correct
11. You want to see the names, modes and data types of the formal parameter
s 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.

12. Examine the following code: CREATE PROCEDURE parent


IS BEGIN
child1;
child2;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END parent;
Neither CHILD1 nor CHILD2 has an exception handler.
When PARENT is invoked, CHILD1 raises a NO_DATA_FOUND exception. What happens ne
xt?
Mark for Review
(1) Points

PARENT handles the exception, then CHILD1 continues to execute.

CHILD1 ends abruptly. PARENT handles the exception and then ends. CHILD2
does not execute. (*)

CHILD1 ends abruptly, PARENT handles the exception, then CHILD2 executes
.

CHILD1 ends abruptly, PARENT also ends abruptly and returns an unhandled
exception.

PARENT does not compile because you cannot use NULL; in an exception han
dler.

Correct

13. User REYHAN creates the following procedure:


CREATE PROCEDURE proc1 AUTHID CURRENT_USER
IS
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM tom.employees;
END;
User BILL wants to execute this procedure. What privileges will BILL need?
Mark for Review
(1) Points

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 doe
s not have SELECT privilege on TOM.EMPLOYEES.

Correct

14. When must AUTHID CURRENT_USER be included in an autonom


ous transaction subprogram? Mark for Review
(1) Points

When declaring Definer's rights

When declaring Invoker's rights (*)

When using COMMIT or ROLLBACK

When using GRANT on the subprogram

Correct

15. User BOB creates procedure MYPROC using the default Defi
ner's Rights. BOB then executes:
GRANT EXECUTE ON bob.myproc TO ted;
When TED invokes BOB.MYPROC, whose privileges are checked?
Mark for Review
(1) Points

TED's privileges
PUBLIC's privileges

SYSTEM's privileges

BOB's privileges (*)

ORACLE's privileges

Correct

Section 8
(Answer all questions in this section)
16. Which of the following are characteristics of PL/SQL su
bprograms but not of anonymous PL/SQL blocks? (Choose three.) Mark for Review
(1) Points
(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

17. A programmer wants to create a PL/SQL procedure named E


MP_PROC. What will happen when the following code is executed?
CREATE OR REPLACE PROCEDURE emp_proc IS
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 999;
DBMS_OUTPUT.PUT_LINE('The salary is: ' || v_salary);
END;
Mark for Review
(1) Points
The statement will raise a NO_DATA_FOUND exception because employee_id 9
99 does not exist.

The statement will fail because the last line of code should be END emp_
proc;

The statement will fail because you cannot declare variables such as v_s
alary inside a procedure.

The procedure will be created successfully. (*)

The statement will fail because the procedure does not have any paramete
rs.

Correct

18. The following are the steps involved in creating, and l


ater modifying and re-creating, a PL/SQL procedure in Application Express. In wh
at sequence should these steps be performed?
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
Mark for Review
(1) Points

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

19. A nested subprogram can only be invoked from the main s


ubprogram. True or False? Mark for Review
(1) Points
True (*)

False

Correct

20. A programmer creates a PL/SQL subprogram which is compi


led and stored in the database. Two separate users then execute an application w
hich invokes this subprogram four times. How many times must the subprogram be r
ecompiled? Mark for Review
(1) Points

Twice

Four times

None (*)

Eight times

Once

Correct
21. Which of the following are characteristics of PL/SQL stored procedures?
(Choose three.) Mark for Review
(1) Points
(Choose all correct answers)

They are named PL/SQL blocks (*)

They must return exactly one value to the calling environment.

They can have an exception section. (*)

They can be invoked from inside a SQL statement.

They can accept parameters. (*)

Correct
22. Suppose you set up a parameter with an explicit OUT mod
e. 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 subprogr
am).

It must be the same type as the matching IN parameter.

It inherits its type from the matching IN parameter.

Correct

23. 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 subprogr
am). (*)

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.

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

25. Procedure SOMEPROC has five parameters named A, B, C, D


, E in that order. The procedure was called as follows:
SOMEPROC(10,20,D=>50);
How was parameter B referenced?
Mark for Review
(1) Points

Positional (*)

Named

A combination of positionally and named

A combination of named and defaulted

Defaulted

Correct

26. You have created the following procedure:


CREATE OR REPLACE PROCEDURE double_it
(p_param IN OUT NUMBER)
IS
BEGIN
p_param := p_param * 2;
END;
Which of the following anonymous blocks invokes this procedure successfully?
Mark for Review
(1) Points

BEGIN
EXECUTE double_it(20);
END;

BEGIN
SELECT double_it(20)
FROM DUAL;
END;

DECLARE
v_result NUMBER(6);
BEGIN
v_result := double_it(20);
END;

DECLARE
v_result NUMBER(6) := 20;
BEGIN
double_it(v_result);
END; (*)

BEGIN
double_it(20);
END;

Correct

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


parameter. Mark for Review
(1) Points

True

False (*)

Correct

28. Which of the following best describes how an IN paramet


er affects a procedure? Mark for Review
(1) Points
It describes the order in which the procedure's statements should be exe
cuted.

It describes which parts of the procedure's code are optional or conditi


onal.

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 proc


edure 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. Examine the following procedure:


CREATE OR REPLACE PROCEDURE smallproc
(p_param IN NUMBER)
IS
BEGIN ....
The procedure is invoked by:
DECLARE
v_param NUMBER := 20;
BEGIN
smallproc(v_param);
END;
Which of the following statements is true?
Mark for Review
(1) Points

p_param is a parameter and v_param is an argument

p_param is a formal parameter and 20 is an actual parameter

p_param is a formal parameter and v_param is an actual parameter (*)

p_param and v_param are both formal parameters, while 20 is an actual pa


rameter

p_param is an actual parameter and v_param is a formal parameter

Correct
31. An INDEX BY TABLE must have a primary key Mark for Review
(1) Points

True (*)

False

Correct

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

Incorrect. Refer to Section 6 Lesson 1.

Section 7
(Answer all questions in this section)
33. Department-id 99 does not exist. What will be displayed
when the following code is executed?
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_deptname
FROM departments WHERE department_id = 99;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20201,'Department does not exist');
END;
Mark for Review
(1) Points

ORA-01403: No Data Found ORA-20201: Department does not exist

ORA-01403: No Data Found

ORA-20201: Department does not exist (*)

None of the above

Correct

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

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

A and B

B and C (*)

A and C

Correct

36. User-defined exceptions must be declared explicitly by


the programmer, but then are raised automatically by the Oracle Server. True or
False? Mark for Review
(1) Points

True

False (*)

Incorrect. Refer to Section 7 Lesson 3.

37. 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 cannot be referenced


in the outer block. (*)
The code will propagate the e_outer_excep back to the calling environmen
t.

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

The code will fail to compile because e_inner_excep was declared but nev
er RAISEd.

Correct

38. Using two nested blocks, a TOO_MANY_ROWS exception is r


aised within the inner block. Which of the following exception handlers will suc
cessfully 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

39. Exceptions declared in a block are considered local to


that block, and global to all its sub-blocks. True or False? Mark for Review
(1) Points

True (*)

False

Correct

40. There are no employees in department 75. What will be d


isplayed when this code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('A');
BEGIN
SELECT last_name INTO v_last_name
FROM employees WHERE department_id = 75;
DBMS_OUTPUT.PUT_LINE('B');
END;
DBMS_OUTPUT.PUT_LINE('C');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('D');
END;
Mark for Review
(1) Points

A
C
D

A
D
(*)

A
B
D

None of the above

Correct
41. Examine the following code fragment. At Line A, you want to raise an ex
ception 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
END IF;
...
Mark for Review
(1) Points

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 erro


r number using PRAGMA EXCEPTION_INIT.

Correct

42. Examine the followiing code. Which exception handlers w


ould successfully trap the exception which will be raised when this code is exec
uted? (Choose two.)
DECLARE
CURSOR emp_curs IS SELECT * FROM employees;
v_emp_rec emp_curs%ROWTYPE;
BEGIN
FETCH emp_curs INTO v_emp_rec;
OPEN emp_curs;
CLOSE emp_curs;
EXCEPTION ...
END;
Mark for Review
(1) Points
(Choose all correct answers)

WHEN CURSOR_NOT_OPEN

WHEN INVALID_CURSOR (*)

WHEN OTHERS (*)

WHEN NO_DATA_FOUND

WHEN INVALID_FETCH

Incorrect. Refer to Section 7 Lesson 2.

43. 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? Mark for Review
(1) Points

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 te


st for WHEN e_null_excep in the exception section.

Correct

44. Which kinds of exceptions are raised implicitly (i.e.,


automatically)? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)

Predefined Oracle Server errors such as NO_DATA_FOUND (*)

User-defined errors

All errors

Non-predefined Oracle Server errors such as ORA-01400 (*)

Correct

45. Which of these exceptions would need to be raised expli


citly by the PL/SQL programmer? Mark for Review
(1) Points

OTHERS

A SELECT statement returns more than one row.

A check constraint is violated.

A SQL UPDATE statement does not update any rows. (*)

A row is FETCHed from a cursor while the cursor is closed.


Correct

46. An attempt to update an employee's salary to a negative


value will violate a check constraint and raise an ORA-02290 exception. Which o
f 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

47. The following EXCEPTION section is constructed correctl


y. True or False?
EXCEPTION
WHEN NO_DATA_FOUND OR TOO_MANY_ROWS
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;
Mark for Review
(1) Points

True (*)

False
Correct

48. Which of these exceptions can be handled by an EXCEPTIO


N section in a PL/SQL block? Mark for Review
(1) Points

A SELECT statement returns no rows

A SELECT statement returns more than one row

Any other kind of exception that can occur within the block

All of the above (*)

None of the above

Correct

49. 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 error-handling 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

50. Examine the following code. Why does the exception hand
ler not follow good practice guidelines?
DECLARE
v_salary employees.salary%TYPE;
BEGIN
SELECT salary INTO v_salary FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;
Mark for Review
(1) Points

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

employee_id 999 does not exist in the employees table.

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

The exception handler should COMMIT the transaction.

Correct

You might also like