Handling Exceptions
1. Which of the following are NOT good practice guidelines for exception handling?
(Choose two.)
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.
EXCEPTION
WHEN ZERO_DIVIDE OR TOO_MANY_ROWS OR NO_DATA_FOUND
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;
True (*)
False
5. Only one exception can be raised automatically during one execution of a PL/SQL block.
True or False?
True (*)
False
6. Which of the following EXCEPTION sections are constructed correctly? (Choose three.)
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
END;
(*)
EXCEPTION
WHEN TOO_MANY_ROWS THEN statement_1;
END;
(*)
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
WHEN OTHERS THEN statement_3;
END;
EXCEPTION
WHEN OTHERS THEN statement_1;
END;
(*)
EXCEPTION
WHEN OTHERS THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
END;
7. 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;
You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.
department_id 75 does not exist in the departments table.
The exception handler should test for the named exception NO_DATA_FOUND. (*)
The exception handler should COMMIT the transaction.
The exception section should include a WHEN TOO_MANY_ROWS exception
handler. (*)
3. There are no employees whose salary is less than 2000. Which exception handlers would
successfully trap the exception which 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;
NO_DATA_FOUND
ZERO_DIVIDE (*)
SQL%ROWCOUNT = 0
OTHERS (*)
OTHER
4. 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;
The code will execute and insert error number 02291 into error_log_table.
The code will fail because SQLCODE has not been declared.
The code will fail because we access error message numbers by using SQLERRNUM, not
SQLCODE.
The code will fail because we cannot use functions like SQLCODE directly in a SQL
statement. (*)
5. What is the correct syntax to associate an exception named EXCEPNAME with the non-
predefined Oracle Server error ORA-02292?
7. Examine the following code. At Line A, you want to raise an exception if the employees
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;
A predefined Oracle Server exception
A constraint violation
A non-predefined Oracle server exception
A user-defined exception (*)
A NO_DATA_FOUND exception
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;
The exception will be raised and Cannot be null will be displayed.
The code will not execute because the syntax of PRAGMA EXCEPTION_INIT is wrong.
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 the INSERT statement is wrong.
10. Which of the following best describes a predefined Oracle Server error?
Has a standard Oracle error number but must be declared and named by the PL/SQL
programmer
Has a standard Oracle error number and a standard name which can be referenced in
the EXCEPTION section (*)
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
11. How would you trap Oracle Server exception ORA-01403: no data found?
WHEN NO DATA FOUND THEN
WHEN ORA-01403 THEN
WHEN NO_DATA_FOUND THEN (*)
WHEN SQL%ROWCOUNT=0 THEN
12. A PL/SQL block executes and an Oracle Server exception is raised. Which of the
following contains the text message associated with the exception?
SQLCODE
SQLERRM (*)
SQL%MESSAGE
SQL_MESSAGE_TEXT
3. You want to display your own error message to the user. What is the correct syntax to do
this?
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.
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;
Message 1
Message 3
Message 1
Message 3
Message 4
Message 1
Message 2
Message 3
Message 4
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.(*)
True
False (*)
DECLARE
v_var1 NUMBER;
BEGIN
DECLARE
v_var2 NUMBER;
BEGIN
v_var1 := 20;
END;
v_var2 := 30;
END;
v_var1 cannot be referenced in the inner block.
v_var1 is a NUMBER variable and cannot be assigned a character string value.
v_var2 cannot be referenced in the outer block. (*)
The block labels are missing.
Nothing is wrong, the code will execute correctly
4. Examine the following code. What is the scope and visibility of the outer blocks
v_myvar?
DECLARE
v_myvar VARCHAR2(20);
BEGIN
DECLARE
v_myvar VARCHAR2(20);
BEGIN
END:
END;
It is in scope and visible in the outer block only.
It is in scope and visible in both blocks.
It is visible in both blocks but in scope only in the outer block.
It is in scope in both blocks but visible only in the outer block. (*)
7. In a pair of nested blocks, block labels such as <<label_name>> must be used for both
blocks or neither block. True or False?
True
False (*)
<<outer>>
DECLARE
v_name VARCHAR2(10) := Smith;
BEGIN
DECLARE
v_name VARCHAR2(10) := Jones;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name);
END;
END;
<<outer>>
DECLARE
v_name VARCHAR2(10) := Smith;
BEGIN
DECLARE
v_name VARCHAR2(10) := Jones;
BEGIN
DBMS_OUTPUT.PUT_LINE(<<outer>>.v_name);
END;
END
<<outer>>
DECLARE
v_name VARCHAR2(10) := Smith;
BEGIN
DECLARE
v_name VARCHAR2(10) := Jones;
BEGIN
DBMS_OUTPUT.PUT_LINE(outer.v_name);
END;
END;(*)
<<outer>>
DECLARE
v_name VARCHAR2(10) := Smith;
BEGIN
<<inner>>
DECLARE
v_name VARCHAR2(10) := Jones;
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name);
END;
END;
True (*)
False
11. 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;
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
12. 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?
True
False (*)
Section 7
1. Exceptions declared in a block are considered local to that block, and global to all its
sub-blocks. True or False? (1) Points
True (*)
False
2. The following code does not violate any constraints and will not raise an ORA-02292
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');
END;
EXCEPTION
WHEN e_constraint_violation THEN
DBMS_OUTPUT.PUT_LINE('Outer block message');
END;
(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.
(*)
10
20 (*)
30
40
200
5. While a PL/SQL block is executing, more than one exception can occur at the same time.
True or False? (1) Points
True
False (*)
True (*)
False
8. Which of the following is NOT an advantage of including an exception handler in a
PL/SQL block? (1) Points
9. 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
END IF;
...
(1) Points
10. Which kinds of exceptions are raised implicitly (i.e., automatically)? (Choose two.) (1)
Points (Choose all correct answers)
Section 7
11. Which of the following best describes a predefined Oracle Server error? (1) Points
Has a standard Oracle error number but must be named by the PL/SQL programmer
Is not raised automatically but must be declared and raised explicitly by the PL/SQL
programmer
Has a standard Oracle error number and a standard name which can be referenced in the
EXCEPTION section (*)
Is associated with an Oracle error number using PRAGMA EXCEPTION_INIT
12. 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?
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.)
(1) Points
True
False (*)
13. Examine the following code. What message or messages will be displayed when this
code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
v_number NUMBER := 27;
BEGIN
v_number := v_number / 0;
SELECT last_name INTO v_last_name FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows were found');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Attempt to divide by zero');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;
(1) Points
14. 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? (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);
FLAG exception_name;
RAISE exception-name; (*)
PRAGMA EXCEPTION_INIT
RAISE(error_number, exception_name);
16. A user-defined exception must be declared as a variable of data type EXCEPTION. True
or False? (1) Points
True (*)
False
17. User-defined exceptions must be declared explicitly by the programmer, but then are
raised automatically by the Oracle Server. True or False? (1) Points
True
False (*)
18. 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;
(1) Points
Section 8
19. You have created procedure MYPROC with a single parameter PARM1 NUMBER.
Now you want to add a second parameter to the procedure. Which of the following will
change the procedure successfully? (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;
21. Which of the following best describes how an IN parameter affects a procedure? (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.
22. 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? (1) Points
23. 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? (1) Points
myproc(5,10,20);
myproc(a=>5,b=>10,20) (*)
myproc(a=>5,b=>10,c=>20)
myproc(5,10,c=>20)
24. Which of the following are characteristics of PL/SQL subprograms but not of
anonymous PL/SQL blocks? (Choose three.) (1) Points (Choose all correct answers)
25. 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? (1) Points
Twice
Four times
None (*)
Eight times
Once
Hosted subprogram
Local subprogram (*)
Limited subprogram
27. A stored PL/SQL procedure can be invoked from which of the following?
A only
A and B
A and C
A, B and C (*)
B and C
28. View and reload your code later by clicking on the History button in the SQL
Commands window. True or False? (1) Points
True
False (*)
29. A programmer wants to create a PL/SQL procedure named EMP_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;
(1) Points
The statement will raise a NO_DATA_FOUND exception because employee_id 999 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_salary inside a
procedure.
The procedure will be created successfully. (*)
The statement will fail because the procedure does not have any parameters.
32. 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?
(1) Points
Positional (*)
Named
A combination of positionally and named
A combination of named and defaulted
Defaulted
33. 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);
Positionally
Named (*)
A combination of positionally and named
A combination of named and defaulted
Defaulted
Section 9
34. 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? (1) Points
True
False (*)
35. Which of the following is a legal location for a function call in a SQL statement?
(Choose 3) (1) Points
(Choose all correct answers)
36. A benefit of user-defined functions is that the function can accept any SQL or PL/SQL
data type. True or False? (1) Points
True
False (*)
37. 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
WHEN NO_DATA_FOUND THEN NULL;
END child1;
Employee_id 9999 does not exist. What happens when PARENT is executed?
(1) Points
CHILD1 handles the exception successfully and ends. PARENT continues to execute and
invokes CHILD2. (*)
CHILD1 ends abruptly, PARENT handles the exception successfully and ends. CHILD2
does not execute.
CHILD1 ends abruptly, then PARENT also ends abruptly with an unhandled exception.
PARENT fails to compile because you cannot have the same exception handler in two
separate subprograms.
38. The following code shows the dependencies between three procedures:
CREATE PROCEDURE parent
IS BEGIN
child1;
child2;
END parent;
You now try to execute:
39. 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) (1) Points (Choose all
correct answers)
Query USER_PARAMETERS
Query USER_SOURCE (*)
Query USER_FUNCTIONS
SHOW PARAMETER my_func;
DESCRIBE my_func; (*)
23
11
66
17 (*)
An error message will be displayed because you cannot nest user-defined functions.
Section 9
42. Which of the following is a difference between a procedure and a function? (1) Points
43. You have created a function named NEWFUNC. You now change some of the function
code, and try to recreate the function by executing:
CREATE OR REPLACE FUNCTION newfunc .... ;
What happens?
(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;
46. How do you specify that you want a procedure MYPROCA to use "Definer's Rights"?
(1) Points
Definer's Rights are the default, therefore no extra code or commands are needed. (*)
The subprogram will fail because the PRAGMA statement must be before IS.
The subprogram will fail because it is missing AUTHID CURRENT_USER before IS.
The compilation will fail because a semicolon after AUTONOMOUS_TRANSACTION is
required. (*)
The program will compile successfully.
Section 6
49. Examine the following code. To create a row trigger, what code should be included at
Line A?
CREATE TRIGGER dept_trigg
AFTER UPDATE OR DELETE ON departments
-- Line A
BEGIN ...
(1) Points
Which of the following are NOT valid at Line A ? (Choose two.) (1) Points (Choose all
correct answers)
Section 6
3. Which of the following will successfully return a user - defined error message?
(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);
4. 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;
EXCEPTION
WHEN OTHERS THEN statement_2;
WHEN NO_DATA_FOUND THEN statement_1;
END;
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN NO_DATA_FOUND THEN statement_2;
WHEN OTHERS THEN statement_3;
END;
EXCEPTION
WHEN OTHERS THEN statement_1;
END; (*)
6. Examine the following code. Why does the exception handler 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;
True (*)
False
8. Which of the following are good practice guidelines for exception handling?
(Choose three.) (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. (*)
The code will fail because you cannot declare a cursor in an inner block.
The code will fail because the cursor is declared in the inner block but is
referenced in the outer block. (*)
The code will execute successfully and display all the employees' salaries.
The code will execute forever because there is no statement to EXIT from the
loop.
10.What will be displayed when the following code is executed? 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
11. 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?
True
False (*)
13. Examine the following code. What is the scope and visibility of the outer
block's v_last_name?
DECLARE
v_last_name VARCHAR2(20);
BEGIN
DECLARE
v_last_name VARCHAR2(20);
BEGIN
...
END:
...
END;
14. The following code does not violate any constraints and will not raise an ORA-
02292 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');
END;
EXCEPTION
WHEN e_constraint_violation THEN
DBMS_OUTPUT.PUT_LINE('Outer block message');
END;
15. Examine the followiing code. Which exception handlers would successfully
trap the exception which will be raised when this code is executed? (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;
(1) Points (Choose all correct answers)
WHEN CURSOR_NOT_OPEN
WHEN INVALID_CURSOR (*)
WHEN OTHERS (*)
WHEN NO_DATA_FOUND
WHEN INVALID_FETCH
16. Which of the following best describes a predefined Oracle Server error? (1)
Points
Has a standard Oracle error number but must be named by the PL/SQL
programmer
Is not raised automatically but must be declared and raised explicitly by the
PL/SQL programmer
Has a standard Oracle error number and a standard name which can be
referenced in the EXCEPTION section (*)
Is associated with an Oracle error number using PRAGMA EXCEPTION_INIT
17. Examine the following code. What message or messages will be displayed
when this code is executed?
DECLARE
v_last_name employees.last_name%TYPE;
v_number NUMBER := 27;
BEGIN
v_number := v_number / 0;
SELECT last_name INTO v_last_name FROM employees
WHERE employee_id = 999;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows were found');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Attempt to divide by zero');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;
18. Which kinds of exceptions are raised implicitly (i.e., automatically)? (Choose
two.) (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 (*)
19. 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
END IF;
...
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);
21. 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)
22. You have created procedure MYPROC with a single parameter PARM1
NUMBER. Now you want to add a second parameter to the procedure. Which of
the following will change the procedure successfully?
24. Which of the following is NOT correct coding for a procedure parameter?
(p_param IN VARCHAR2)
(p_param VARCHAR2)
(p_param VARCHAR2(50)) (*)
(p_param employees.last_name%TYPE)
(p_param IN OUT VARCHAR2)
25. Which of the following statements about actual parameters is NOT true?
27. Which of the following are characteristics of PL/SQL subprograms but not
of anonymous PL/SQL blocks? (Choose three.) (Choose all correct answers)
28. One PL./SQL subprogram can be invoked from within many applications. True
or False?
True (*)
False
Twice
Four times
None (*)
Eight times
Once
31. A PL/SQL stored procedure can accept one or more input parameters and can
return one or more output values to the calling environment. True or False?
True (*)
False
32. A PL/SQL procedure named MY_PROC1 has been successfully created in the
database. The procedure has no parameters. Which of the following will
successfully invoke the procedure in Application Express? (Choose two.) (Choose
all correct answers)
DECLARE
v_var1 NUMBER := 20;
BEGIN
my_proc1(v_var1);
END;
EXECUTE my_proc1;
BEGIN
my_proc1;
END; (*)
IN (*)
OUT
NUMBER
VARIABLE
CONSTANT
Positionally
Named (*)
A combination of positionally and named
A combination of named and defaulted
Defaulted
myproc(40);
myproc(10, B => 30, 50);
myproc(C => 25);
All of the above
None of the above (*)
CHILD1 ends abruptly, PARENT handles the exception, then CHILD2 executes.
CHILD1 ends abruptly, PARENT also ends abruptly and returns an unhandled
exception. xception.
PARENT does not compile because you cannot use NULL; in an exception handler.
38. 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)
(Choose all correct answers)
Query USER_PARAMETERS
Query USER_SOURCE (*)
Query USER_FUNCTIONS
SHOW PARAMETER my_funct;
DESCRIBE my_funct; (*)
39. You want to remove the procedure NO_NEED from your schema. You execute:
DROP PROCEDURE no_need;
Which Data Dictionary views are updated automatically?
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE
All of the above. (*)
None of the above.
40. 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?
myfunc('Crocodile') := v_var1;
myfunc(v_var1) := 'Crocodile';
myfunc(v_var1, 'Crocodile');
v_var1 := myfunc('Crocodile'); (*)
myfunc('Crocodile', v_var1);
23
11
66
17 (*)
42. You have created a function named NEWFUNC. You now change some of the
function code, and try to recreate the function by executing:
CREATE OR REPLACE FUNCTION newfunc .... ;
What happens?
44. You try to create a function named MYFUNC. The function does not compile
correctly because there are errors in your code. Which Dictionary view can you
query to see the errors?
USER_SOURCE
USER_ERRORS (*)
USER_OBJECTS
USER_DEPENDENCIES
USER_COMPILES
USER_OBJECTS
USER_DEPENDENCIES
USER_COMPILES
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;
They automate repetitive formulas which otherwise you would have to type in
full
every time you used them. (*)
They execute faster than system-defined functions such as UPPER and LOWER.
They allow you to execute DML from inside a SELECT statement.
They allow you to use functions which return a BOOLEAN.
They are stored on your local PC, not in the database.
Nowhere in a query.
49. How do you specify that you want a procedure MYPROCA to use Invoker's
Rights?
50. How do you specify that you want a procedure MYPROCA to use "Definer's
Rights"?
TEST 1...............................................
True (*)
False
Correct
2. An INDEX BY TABLE type can only have one data field. Mark for Review (1)
Points
True (*)
False
Correct
3. 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
uery (*)
Correct
5. Why will the following statement fail? SELECT employee_id, tax(p_value =>
salary) FROM employees; Mark for Review (1) Points
6. In a SELECT statement, where can a function NOT be used ? Mark for Review
(1) Points
In a WHERE clause.
In an ORDER BY clause.
tion 9 Lesson 1.
7. Which of the following best describes a stored function ? Mark for Review (1)
Points
e value. (*)
IN parameter.
arameters.
ogram.
Correct
8. Why will this function not compile correctly? CREATE FUNCTION bad_one IS
BEGIN RETURN NULL; END bad_one; Mark for Review (1) Points
ATE.
The body of the function must contain at least one executable statement (as well
as RETURN).
tion 9 Lesson 1.
9. A function must have at least one IN parameter, and mus t return exactly one
value. Mark for Review (1) Points
True
False (*)
Correct
10. 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
N clause.
well as a precision.
11. You try to create a function named MYFUNC. The function does not compil e
correctly because there are errors in your code. Which Dictionary view can you
query to see the errors? Mark for Review (1) Points
USER_SOURCE
USER_ERRORS (*)
USER_OBJECTS
USER_DEPENDENCIES
USER_COMPILES
Correct
12. 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? (Choo se two) Mark
for Review (1) Points
Query USER_PARAMETERS
Query USER_FUNCTIONS
Correct
13. You want to remove the procedure NO_NEED from your sche ma. You
execute: DROP PROCEDURE no_need; Which Data Dictionary views are updated
automatically? Mark for Review
(1) Points
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE
Correct
DROP PROCEDURE child2; What happens? Mark for Review (1) Points
dependent on it.
as well.
Correct
15. 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
M.EMPLOYEES (*)
EXECUTE on REYHAN.PROC1
SELECT on TOM.EMPLOYEES
None of the above. The procedure will fa il to compile because REYHAN does not
have SELECT privilege on TOM.EMPLOYEES.
Correct
16. How do you specify that you want a procedure MYPROCA to use "Definer's
Rights"? Mark for Review (1) Points
Definer's Rights are the default, theref ore no extra code or commands are
needed. (*)
Correct
17. When must AUTHID CURRENT_USER be included in an autonom ous
transaction subprogram? Mark for Review (1) Points
Correct
18. There are no employees in department 99. What message o r messages will
be displayed when the following code is executed? 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; Mark for Review (1) Points
Message 1
Message 3
Message 1
Message 2
Message 1
Message 3 Message 4
Message 1
Message 4 (*)
Correct
19. Which of the following will successfully return a userdefined error message?
Mark for Review (1) Points
RAISE_APPLICATION_ERROR('Error Raised',
22001);
RAISE_APPLICATION_ERROR(-20257,'Error ra
ised'); (*)
RAISE_APPLICATION_ERROR(-22001,'Error Ra
ised');
RAISE_APPLICATION_ERROR('Error Raised',
20257);
Correct
True
False (*)
Correct
FLAG exception_name;
PRAGMA EXCEPTION_INIT
RAISE(error_number, exception_name);
Correct
22. 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
23. 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
CD
D (*)
B D
Correct
24. The following code does not violate any constraints and will not raise an
ORA-02292 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'); END; EXCEPTION WHEN
e_constraint_violation THEN DBMS_OUTPUT.PUT_LINE('Outer block
message'); END; Mark for Review (1) Points
The code will fail because the exception is declared in the inner block but is
referenced in the outer block. (*)
The code will fail because line 4 should read: PRAGMA EXCEPTION_INIT(-2292,
e_constraint_violation);
Correct
25. 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
Correct
True (*)
False
Correct
27. While a PL/SQL block is executing, more than one except ion can occur at
the same time. True or False? Mark for Review (1) Points
True
False (*)
Correct
28. 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
in an exception handler.
ployees table.
transaction.
Correct
29. Which of the following best describes a PL/SQL exceptio n? Mark for Review
(1) Points
An error occurs during execution which d isrupts the normal operation of the
program. (*)
Correct
30. 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
WHEN CURSOR_NOT_OPEN
WHEN NO_DATA_FOUND
WHEN INVALID_FETCH
Correct
Correct 31. How can you retrieve the error code and error message of any
Oracle Ser ver exception? Mark for Review (1) Points
RM (*)
By using RAISE_APPLICATION_ERROR
Correct
32. Which of the following best describes a user-defined ex ception? Mark for
Review (1) Points
NO_DATA_FOUND
h as ORA-01400
Correct
33. Examine the following code fragment. At Line A, you wan t to raise an
exception if the fetched salary value is greater than 30000. How c an 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;
ption section.
Test for WHEN OTHERS in the exception se ction, because WHEN OTHERS traps
all exceptions.
Correct
DECLARE
DECLARE
DECLARE
DECLARE
Correct
35. Which of these exceptions would need to be raised expli citly by the PL/SQL
programmer? Mark for Review (1) Points
OTHERS
row.
ny rows. (*)
cursor is closed.
Correct
e calling environment.
atement.
Correct
The statement will fail because you cann ot declare variables such as v_salary
inside a procedure.
ly. (*)
Correct
38. 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
39. Which of the following are benefits of using PL/SQL sub programs rather than
anonymous blocks? (Choose three.) Mark for Review (1) Points
Easier to write
Correct
the following?
A only
A and B
A and C
A, B and C (*)
B and C
Correct 41. What is another name for a nested subprogram? Mark for Review
(1) Points
Hosted subprogram
Limited subprogram
Correct
42. A procedure will execute faster if it has at least one parameter. Mark for
Review (1) Points
True
False (*)
Correct
43. Which of the following can NOT be used as the datatype of a procedure
parameter? Mark for Review (1) Points
Correct
(1) Points
Correct
45. 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;
BEGIN
BEGIN
DECLARE
v_result NUMBER(6); BEGIN v_result := double_it(20); END;
DECLARE
BEGIN
double_it(20); END;
Correct
46. Which of the following statements about actual paramete rs is NOT true?
Mark for Review (1) Points
a variable (*)
atatype
datatype
Correct
(1) Points
IN (*)
OUT
NUMBER
VARIABLE
CONSTANT
Correct
Positionally
Named (*)
Defaulted
Correct
Positional (*)
Named
Defaulted
Correct
50. What are the type of parameter modes? Mark for Review
(1) Points
Correct
OPTIMIZE_LEVEL
PLSQL_OPTIMIZE_LEVEL (*)
PLSQL_CODE_TYPE
PLSQL_LEVEL
USER_PLSQL_OPTIMIZE
Correct
2. To determine the current setting for PLSQL_OPTIMIZE_LEV EL, query the data
dictionary view USER_PLSQL_OBJECTS_SETTING. True or False? Mark for Review
(1) Points
True
False (*)
Correct
de. (*)
Correct
o a PL/SQL variable.
Disables all warning categories, then en
Correct
and
True
False (*)
Correct
True (*)
False
Correct
ctionary.
provided.
Correct
8. What are the two methods for obfuscating PL/SQL subprog rams? (Choose
two) Mark for Review (1) Points
DBMS_DDL.CREATE_WRAPPED (*)
DBMS_DDL.WRAP
DBMS_DML.CREATE_WRAPPED
Correct
True
False (*)
Correct
True
False (*)
Correct
11. Identify some benefits of using conditional compilation. (Choose two) Mark
for Review (1) Points
Use new features with the latest databas e release and disable them with older
database versions (*)
hy PL/SQL subprogram.
12. How would you determine the current Oracle database ver sion? Mark for
Review (1) Points
DBMS_DB_VERSION.RELEASE
DBMS_DB_VERSION.VERSION (*)
DBMS_DB_VERSION.VER_LE_10
DBMS_DB_VERSION.VER_LE_11
Correct
13. Function FETCH_EMP references the EMPLOYEES table. The table is modified
by: ALTER TABLE employees ADD (resume CLOB); When will the ORACLE server
try to recompile FETCH_EMP automatically? Mark fo r Review (1) Points
p COMPILE; is executed
CH_EMP (*)
he EMPLOYEES table
Correct
Which one of the following statements is true? Mark for Review (1) Points
Correct
15. Which of the following will display dependency informat ion which has been
generated by executing the DEPTREE_FILL procedure? (Choose tw o.) Mark for
Review (1) Points
Correct
16. The PL/SQL variable V_LAST_NAME is used to store fetche d values of the
LAST_NAME column of the EMPLOYEES table. To minimize dependency failures,
the variable should be declared as: v_last_name VARCHAR2(25);
(1) Points
True
False (*)
Correct
17. A SELECT from the DEPTREE table displays table LOCATION S at nested level
0 and procedure LOCPROC at nested level 2. This shows that LOC PROC is
directly dependent on LOCATIONS. True or False? Mark for Review
(1) Points
True
False (*)
Correct
18. User BOB wants to know which objects reference his DEPA RTMENTS table.
Which of the following must he execute to populate the DEPTREE_TE MPTAB
table? Mark for Review (1) Points
BEGIN
utldtree('DEPARTMENTS'); END;
Correct
19. When a table is dropped, all PL/SQL subprograms that re ference the table
are automatically dropped. True or False? Mark for Review
(1) Points
True
False (*)
Correct
20. Which of the following will display the number of inval id package bodies in
your schema? Mark for Review (1) Points
True (*)
False
Correct
True
False (*)
Correct
ally recorded as invalid if its base object changes and that new status is relay ed
to the dependent object's status and automatically marked as invalid. True or
False? Mark for Review (1) Points
True
False (*)
Correct
True (*)
False
Correct
ODE = SIGNATURE
DE = SIGNATURE
DE = SIGNATURE (*)
E = SIGNATURE
Correc
PLSQL Final Exam Semester 1 - Part II
Twice
Four times
None (*)
Eight times
Once
2. Which of the following are benefits of using PL/SQLsubprograms rather than anonymous
blocks? (Choose three.) (1) Points
(Choose all correct answers)
Easier to write
Better data security (*)
Easier code maintenance (*)
Faster performance (*)
Do not need to declare variables
The statement will raise a NO_DATA_FOUND exception because employee_id 999 does not
exist.
The statement will fail because the last line of code should be END emp_proc; of code should
be END emp_proc;
The statement will fail because you cannotdeclare variables such as v_salary inside a
procedure.
The procedure will be created successfully.(*)
The statement will fail because the proceduredoes not have any parameters.
5. The following are the steps involved in creating, andlater modifying and re-creating, a
PL/SQL procedure in
pplicationExpress. In what sequence should these steps be performed?
(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
6. A PL/SQL procedure named MYPROC has already been created and storedin the database.
Which of the following will successfully re-create the procedure after some changes have
been made to the code? (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 mustbe dropped before it can be re-created.
myproc(40);
myproc(10, B => 30, 50);
myproc(C => 25);
All of the above
None of the above (*)
8. Suppose you set up a parameter with an explicit IN mode. What is true about that
parameter? (1) Points
10. 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? (1) Points
Positional (*)
Named
A combination of positionally and named
A combination of named and defaulted
Defaulted
11. Using nested blocks, when is it necessary to label the outer block?. (1) Points
12. Which of the following will display the value 'Smith'? (1) Points
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
DECLARE
v_name VARCHAR2(10) := 'Jones';
BEGIN
DBMS_OUTPUT.PUT_LINE(v_name);
END;
END;
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
DECLARE
v_name VARCHAR2(10) := 'Jones';
BEGIN
DBMS_OUTPUT.PUT_LINE(<<outer>>.v_name);
END;
END;
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
DECLARE
v_name VARCHAR2(10) := 'Jones';
BEGIN
DBMS_OUTPUT.PUT_LINE(outer.v_name);
END;
END;(*)
<<outer>>
DECLARE
v_name VARCHAR2(10) := 'Smith';
BEGIN
<<inner>>
DECLARE
v_myvar1 := 100;
END;
v_myvar2 := 100; v END; (1) Points
True
False (*)
BEGIN
OPEN emp_curs;
LOOP
The code will fail because you cannot declarea cursor in an inner block. a cursor in an inner
block.
The code will fail because the cursor is declared in the inner block but is referenced in the
outer block. (*)
The code will execute successfully anddisplay all the employees' salaries.
The code will execute forever because there is no statement to EXIT from the loop.
BEGIN
v_myvar := 10;
DECLARE
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; (1) Points
10
20 (*)
30
40
200
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
It will fail to compile because you cannothave a subblock inside an exception section.
It will fail to compile because e_excep1 isout of scope in the subblock.
It will fail to compile because you cannotdeclare more than one exception in the same block.
It will compile successfully and return anunhandled e_excep2 to the calling environment. (*)
IS BEGIN
RETURN (a+b);
END ADD_EM;
Which one of the following blocks will NOT work correctly? (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 BEGIN
x:= add_em;
END;
True
False (*)
20. 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;
myfunc('Crocodile') := v_var1;
myfunc(v_var1) := 'Crocodile';
myfunc(v_var1, 'Crocodile');
v_var1 := myfunc('Crocodile'); (*)
myfunc('Crocodile', v_var1);
END badfunc;
(1) Points
Mark for Review
P_PARAM must be declared AFTER the RETURN
clause.
P_PARAM must have a default value.
The datatype of the IN parameter cannot have
22. Which of the following is a difference between a procedure and a function? (1) Points
23. You want to remove the procedure NO_NEED from yourschema. You execute:
DROP PROCEDURE no_need;
Which Data Dictionary views are updated automatically? (1) Points
USER_PROCEDURES
USER_OBJECTS
USER_SOURCE
All of the above. (*)
None of the above.
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END parent;
IS BEGIN
child1;
child2;
END parent;
You now try to execute:
26. User BOB creates procedure MYPROC using the default Definer'sRights. BOB then
executes:
TED's privileges
PUBLIC's privileges
SYSTEM's privileges
BOB's privileges (*)
ORACLE's privileges
27. How do you specify that you want a procedure MYPROCA touse "Definer's Rights"? (1)
Points
28. You have created procedure MYPROC with a singleparameter PARM1 NUMBER. Now
you want to add a second parameter to theprocedure. Which of the following will change the
procedure successfully? (1) Points
The procedure cannot be modified. Once aprocedure has been created, the number of
parameters cannot be changed.
CREATE OR REPLACE PROCEDURE someproc(parm1 NUMBER, parm2 NUMBER);
(You do not need to repeat the detailed code of the procedure, only theheader)
REPLACE PROCEDURE someproc(parm1 NUMBER, parm2 NUMBER)
IS
BEGIN ...
CREATE OR REPLACE PROCEDURE MYPROC
(parm1 NUMBER, parm2 NUMBER)
IS
BEGIN ... (*)
29. Which of the following statements about actualparameters is NOT true? (1) Points
30. A procedure will execute faster if it has at least oneparameter. (1) Points
True
False (*)
31. Which of the followingis NOT correct coding for a procedure parameter? (1) Points
(p_param IN VARCHAR2)
(p_param VARCHAR2)
(p_param VARCHAR2(50)) (*)
(p_param employees.last_name%TYPE)
(p_param IN OUT VARCHAR2)
32. You want to create a procedure named SOMEPROC whichaccepts a single parameter
named SOMEPARM. The parameter can be up to 100characters long. Which of the following
is correct syntax to do this? (1) Points
33. Which of the following best describes how an INparameter affects a procedure? (1) Points
34. Examine the following code fragment. At Line A, you wantto 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 employeesWHERE employee_id = 100;
IF v_salary > 30000 THEN--Line A
END IF;
...
(1) Points
35. An attempt to insert a null value into a NOT NULL tablecolumn raises an ORA-01400
exception. How can you code an exceptionhandler to trap this exception? (1) Points
36.Examine the followiing code. Which exception handlers wouldsuccessfully trap the
exception which will be raised when this code isexecuted? (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;
(1) Points (Choose all correct answers)
WHEN CURSOR_NOT_OPEN
WHEN INVALID_CURSOR (*)
WHEN OTHERS (*)
WHEN NO_DATA_FOUND
WHEN INVALID_FETCH
37. Which of these exceptions would need to be raisedexplicitly by the PL/SQL programmer?
(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.
38. How can you retrieve the error code and error message ofany Oracle Server exception?
(1) Points
By using the functions SQLCODE and SQLERRM (*)
By using the functions SQLCODE and SQLERR
By using RAISE_APPLICATION_ERROR
By defining an EXCEPTION variable and using PRAGMA EXCEPTION_INIT
39. Examine the following code. What message or messageswill be displayed when this code
is executed?
DECLARE
v_last_name employees.last_name%TYPE;
v_number NUMBER := 27;
BEGIN
v_number := v_number / 0;
SELECT last_name INTO v_last_name FROM employeesWHERE employee_id = 999;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows were found');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Attempt to divide by zero');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END; Mark for Review
SELECT last_name INTO v_last_name FROM employeesWHERE employee_id = 999;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No rows were found');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Attempt to divide by zero');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;
(1) Points
41. Which one of the following statements about user-defined functions is NOT true? (1)
Points
42. Which of the following are NOT allowed in a functionwhich is used inside a SQL
statement which updates the EMPLOYEES table? (Choose two). (1) Points (Choose all
correct answers)
44. While a PL/SQL block is executing, more than oneexception can occur at the same time.
True or False? (1) Points
True
False (*)
EXCEPTION
THEN statement_1;
statement_2;
WHEN OTHERS
THEN statement_3;
END;
(1) Points
True (*)
False
46. Which of the followingare good practice guidelines for exception handling? (Choose
three.) (1) Points (Choose all correct answers)
Test your code with different combinations ofdata 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 thecalling environment.
Handle specific named exceptions wherepossible, instead of relying on WHEN OTHERS. (*)
47. A user-defined exception must be declared as a variableof data type EXCEPTION. True
or False? (1) Points
True (*)
False
B
C
A and B
B and C (*)
A and C
49. User-defined exceptions must be declared explicitly bythe programmer, but then are
raised automatically by the Oracle Server. True or False? (1) Points
True
False (*)
50. Department-id 99 does not exist. What will be displayedwhen the following code is
executed?
DECLARE
v_deptname departments.department_name%TYPE;
BEGIN
SELECT department_name INTO v_deptnameFROM departments WHERE department_id =
99;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20201,'Department does not exist');
END;
(1) Points
Mark for Review (1) Points The subprogram will fail because it is missing AUTHID
CURRENT_USER before IS. The autonomous transaction subprogram will fail
because it must include COMMIT or ROLLBACK. (*) The compilation will fail
because a semicolon after AUTONOMOUS_TRANSACTION is not needed. The
program will compile successfully. Incorrect. Refer to Section 9 Lesson 6. 2. 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
4. 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 5. The following
function has been created:
The sal parameter should specify the IN keyword. The RETURN NUMBER has a
scale and precision. (*) There should be parentheses (brackets) around
NVL(comm_pct,0)*12*sal The END; statement should not include the function
name. Correct 8. 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. Correct 9. 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; (*) Correct 10. 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 (*) Incorrect. Refer to Section 9 Lesson 6. 11. 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 Incorrect. Refer to Section 9 Lesson 1. 12. A
PL/SQL function can have IN OUT parameters. True or False? Mark for Review (1)
Points
True False (*) Correct 13. 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. Correct
14. 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); Correct 15. 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. (*) Correct
LESSON 2
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);
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. 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 One or more IN
parameters (*) An OUT parameter COMMIT; Correct 6. 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
LESSON 3 1. 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 LIKE USER%; Read the online Oracle documentation at
http://technet.oracle.com. SELECT * FROM dict WHERE table_name LIKE 'USER
%TAB%';
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. Correct 3. 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;
Mark for Review (1) Points fn_index FN_INDEX fn_index FN_INDEX No output will
be displayed (*) Correct 5. 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 (*)
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. Correct 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. Correct 8. 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
LESSON 4
1. Which dictionary view will list all the PL/SQL subprograms in your schema?
Mark for Review (1) Points user_source
(*) 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 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
When call_ins_emp is executed, 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
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 Correct 2. 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 1 2 (*) 3 4 8 Correct 3. 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 Correct
4. 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; Correct 5. 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 6. 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 Correct
2. 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 (*) Incorrect. Refer
to Section 9 Lesson 6. 3. Procedure GET_EMPS includes a SELECT ... FROM
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. (*) Incorrect. Refer to Section 9 Lesson 6. 4. 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 ...
HARRY now executes the procedure. Which employees table will be queried?
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. Correct