Final Sem 1 v2 PLSQL
Final Sem 1 v2 PLSQL
Final Sem 1 v2 PLSQL
Review your answers, feedback, and question scores below. An asterisk (*) indicates a
correct answer.
Section 6
1. How can you retrieve the error code and error message of any
Mark for Review
Oracle Server exception?
(1) Points
Correct
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
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;
WHEN CURSOR_NOT_OPEN
WHEN INVALID_CURSOR (*)
WHEN OTHERS (*)
WHEN NO_DATA_FOUND
WHEN INVALID_FETCH
TOO_MANY_ROWS (*)
NO_DATA_FOUND (*)
OTHERS
ZERO_DIVIDE (*)
E_INSERT_EXCEP
Correct
Correct
6. The following exception handler will successfully insert the
Mark for Review
Oracle error number and error message into a log table
(1) Points
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;
True
False (*)
Correct
EXCEPTION
WHEN NO_DATA_FOUND THEN statement_1;
WHEN OTHERS THEN statement_2;
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;
(*)
Correct
True
False (*)
Correct
Correct
True (*)
False
Correct
Page 1 of 5
Section 6 11. 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;
Correct
12. 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 (*)
Correct
13. There are no employees in department 99. What message or 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;
Message 1
Message 2
Message 1
Message 3
Message 4
Message 1
Message 4
(*)
Correct
14. A user-defined exception must be declared as a variable of data type
EXCEPTION. True or False? Mark for Review
(1) Points
True (*)
False
Correct
15. What will happen when the following code is executed?
DECLARE
e_excep1 EXCEPTION;
e_excep2 EXCEPTION;
BEGIN
RAISE e_excep1;
EXCEPTION
WHEN e_excep1 THEN BEGIN
RAISE e_excep2; END;
END;
It will fail to compile because you cannot declare more than one exception in the
same block.
Correct
16. What will happen when the following code is executed?
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.
Correct
17. 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;
The code will propagate the e_outer_excep back to the calling environment.
The code will execute successfully and 'Outer Raised' will be displayed.
The code will fail to compile because e_inner_excep was declared but never
RAISEd.
Correct
18. Examine the following code which shows three levels of nested block. What
is the scope of the variable v_middle_var?
Correct
19. The following code will execute correctly. True or False?
DECLARE
v_myvar1 NUMBER;
BEGIN
DECLARE
v_myvar2 NUMBER;
BEGIN
v_myvar1 := 100;
END;
v_myvar2 := 100; v END;
False (*)
Correct
20. 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;
It is in scope in both blocks, but visible only in the outer block. (*)
Correct
Section 7 21. Which of the following statements about actual parameters is NOT
true? Mark for Review
(1) Points
An actual parameter is declared in the calling environment, not in the called
procedure
The datatypes of an actual parameter and its formal parameter must be compatible
It passes a value into the procedure when the procedure is invoked. (*)
Correct
24. 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? Mark for Review
(1) Points
ALTER PROCEDURE myproc ADD (parm2 NUMBER);
The procedure cannot be modified. Once a procedure has been created, the number of
parameters cannot be changed.
(p_param VARCHAR2)
(p_param employees.last_name%TYPE)
Correct
26. 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 and v_param are both formal parameters, while 20 is an actual parameter
Named (*)
Defaulted
SOMEPROC(10,20,D=>50);
Named
Defaulted
Correct
30. The following procedure has been created:
Correct
BEGIN (*)
IS or AS (*)
DECLARE
END (*)
Correct
32. 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 (*)
Correct
33. 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.) Mark for Review
(1) Points (Choose all correct answers)
DECLARE
v_var1 NUMBER := 20;
BEGIN
my_proc1(v_var1);
END;
EXECUTE my_proc1;
BEGIN
my_proc1;
END;
(*)
(*)
A and B
A and C
A, B and C (*)
B and C
Correct
35. 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? Mark
for Review
(1) Points
True (*)
False
Correct
36. 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
Twice
Four times
None (*)
Eight times
Once
Correct
Section 8 37. Examine the following code:
11
66
17 (*)
An error message will be displayed because you cannot nest user-defined functions.
Correct
38. You have created a function named NEWFUNC. You now change some of
the function code, and try to recreate the function by executing:
The command fails because you should execute: CREATE AND REPLACE ....;
A second function named NEWFUNC_2 is created.
Correct
39. 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 function can be used inside a SQL statement, while a procedure cannot. (*)
Correct
40. Which of the following best describes a stored function? Mark for
Review
(1) Points
A subprogram that must return exactly one value. (*)
Correct
Section 8 41. A function must have at least one IN parameter, and must return
exactly one value. Mark for Review
(1) Points
True
False (*)
Correct
42. In a SELECT statement, where can a function NOT be used? Mark for
Review
(1) Points
In a GROUP BY or HAVING clause.
In a WHERE clause.
In an ORDER BY clause.
Correct
43. 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
None of the above. The procedure will fail to compile because REYHAN does not
have SELECT privilege on TOM.EMPLOYEES.
Correct
44. 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.
Correct
45. Which of the following are NOT allowed in a function which is used inside a
SQL statement which updates the EMPLOYEES table? (Choose two). Mark for
Review
(1) Points (Choose all correct answers)
SELECT .... FROM departments ....;
COMMIT; (*)
A RETURN statement.
Correct
46. Which one of the following statements about user-defined functions is NOT
true? Mark for Review
(1) Points
They can execute spell-checking routines.
They can be combined (nested) together, similar to nesting system functions, for
example INITCAP(SUBSTR( .....)).
They can allow you to COMMIT from inside a SELECT statement. (*)
Correct
47. What is one of the advantages of using user-defined functions in a SQL
statement? Mark for Review
(1) Points
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.
USER_OBJECTS
USER_SOURCE (*)
USER_SUBPROGRAMS
Correct
49. 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_FUNCTIONS
Correct
50. The following code shows the dependencies between three procedures:
Correct