Sie sind auf Seite 1von 21

FINAL EXAM SEMESTER 1

1. Consider the following


cursor: Mark for Review
(1) Points
CURSOR c IS
SELECT e.last_name,
e.salary,
d.department_name
FROM employees e
JOIN departments d
USING(department_id)
WHERE
e.last_name='Smith'
FOR UPDATE;

When the cursor is


opened and rows are
fetched, what is locked?

In the EMPLOYEES table, only the 'Smith' rows are locked.


Nothing in the DEPARTMENTS table is locked.
Nothing is locked because the cursor was not declared with
NOWAIT.
The whole EMPLOYEES table is locked.
Each 'Smith' row is locked and Smith's matching rows in
DEPARTMENTS are locked. No other rows are locked in
either table. (*)
The whole EMPLOYEES and DEPARTMENTS tables are
locked.

Correct

2. Examine the following code:


Mark for Review
DECLARE (1) Points
CURSOR c IS SELECT * FROM employees FOR UPDATE;
c_rec c%ROWTYPE;
BEGIN
OPEN c;
FOR i IN 1..20 LOOP
FETCH c INTO c_rec;
IF i = 6 THEN
UPDATE employees SET first_name = 'Joe'
WHERE CURRENT OF c;
END IF;
END LOOP;
CLOSE c;
END;

Which employee row or rows will be updated when this block is


executed?

No rows will be updated because you locked the rows when


the cursor was opened.
None of these.
The block will not compile because the cursor should have
been declared .... FOR UPDATE WAIT 5;
The first 6 fetched rows will be updated.
The 6th fetched row will be updated. (*)

Correct

3. Look at these declarations:


Mark for Review
DECLARE (1) Points
CURSOR dept_loc_cursor IS
SELECT department_id, department_name, location_name
FROM departments d, locations l
WHERE d.location_id = l.location_id;
v_dept_loc dept_loc_cursor%ROWTYPE;

How many fields (columns) does V_DEPT_LOC contain?

None
Four
Two, because the cursor joins two tables
Three (*)

Correct

4. Examine the following code fragment:


Mark for Review
DECLARE (1) Points
CURSOR emp_curs IS
SELECT first_name, last_name FROM employees;
v_emp_rec emp_curs%ROWTYPE;
BEGIN
...
FETCH emp_curs INTO v_emp_rec;
DBMS_OUTPUT.PUT_LINE(.. Point A ...);
...

To display the fetched last name, what should you code at Point
A?

None of these.
v_emp_rec.last_name (*)
v_emp_rec(last_name)
last_name
v_emp_rec

Correct
5. The DEPARTMENTS table contains four columns. Examine the
following code: Mark for Review
(1) Points
DECLARE
CURSOR dept_curs IS
SELECT * FROM departments;
v_dept_rec dept_curs%ROWTYPE;
BEGIN
OPEN dept_curs;
FETCH dept_curs INTO v_dept_rec;
...

Which one of the following statements is true?

The FETCH will fail because the structure of v_dept_rec


does not match the structure of the cursor.
The block will fail because the declaration of v_dept_rec is
invalid.
v_dept_rec contains the first four rows of the departments
table.
v_dept_rec contains the first row of the departments table.
(*)

Correct

6.Look at the following


code: Mark for
Review
DECLARE (1) Points
CURSOR emp_cursor IS
SELECT * FROM
employees;
BEGIN
FOR emp_record IN
emp_cursor LOOP
DBMS_OUTPUT.PUT_LI
NE( --Point A -- );
END LOOP;
END;

To display the salary of an


employee, what code
should you write at Point
A?

TO_CHAR(salary)
emp_record.salary (*)
emp_cursor.salary
employees.salary
emp_record.employees.salary
Correct

7. What is wrong with the following code?


Mark for
BEGIN Review
FOR emp_rec IN (1) Points
(SELECT * FROM employees WHERE ROWNUM < 10 ) LOOP
DBMS_OUTPUT.PUT_LINE(emp_rec%ROWCOUNT ||
emp_rec.last_name):
END LOOP;
END;

The cursor has not been opened.


You cannot reference %ROWCOUNT with a cursor FOR loop
using a subquery. (*)
The field EMP_REC.LAST_NAME does not exist.
You cannot use FOR UPDATE NOWAIT with a cursor FOR
loop using a subquery.
You cannot use ROWNUM with a cursor FOR loop.

Correct

8. What is wrong with the following code?


Mark for
DECLARE Review
CURSOR dept_curs IS SELECT * FROM departments; (1) Points
BEGIN
FOR dept_rec IN dept_curs LOOP
DBMS_OUTPUT.PUT_LINE(dept_curs%ROWCOUNT ||
dept_rec.department_name):
END LOOP;
DBMS_OUTPUT.PUT_LINE(dept_rec.department_id);
END;

The cursor DEPT_CURS has not been closed.


You cannot use %ROWCOUNT with a cursor FOR loop.
The implicitly declared record DEPT_REC cannot be
referenced outside the cursor FOR loop. (*)
The cursor DEPT_CURS has not been opened.
Nothing is wrong, this code will execute successfully.

Correct

9. Place the following statements in the correct sequence:


Mark for

A. OPEN my_curs; Review


B. CLOSE my_curs; (1) Points
C. CURSOR my_curs IS SELECT my_column FROM
my_table;
D. FETCH my_curs INTO my_variable;

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

Correct

10. What is wrong with the following code?


Mark for
DECLARE Review
CURSOR dept_curs IS SELECT department_name FROM (1) Points
departments;
v_dept_name departments.department_name%TYPE;
BEGIN
OPEN dept_curs;
LOOP
FETCH dept_curs INTO v_dept_name;
EXIT WHEN dept_curs%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(v_dept_name);
CLOSE dept_curs;
END LOOP;
END;

The loop should be a WHILE loop, not a basic loop.


The OPEN statement should be inside the loop.
The EXIT WHEN ... statement should be coded outside the
loop.
Nothing is wrong; all the rows will be FETCHed and
displayed.
The CLOSE statement should be coded after END LOOP; (*)

Correct

11.What will happen when the


following code is executed? Mark for
Review
DECLARE (1) Points
CURSOR emp_curs IS
SELECT salary FROM
employees;
v_salary
employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_salary;
DBMS_OUTPUT.PUT_LINE(v_sala
ry);
CLOSE emp_curs;
END;
The lowest salary value will be fetched and
displayed.
The execution will fail and an error message will
be displayed. (*)
All employees' salaries will be fetched and
displayed.
The first employee's salary will be fetched and
displayed.

Correct

12. An explicit cursor must always be declared, opened,


and closed by the PL/SQL programmer. True or False? Mark for
Review
(1) Points

TRUE
FALSE (*)

Incorrect. Refer to Section 5


Lesson 1.

13. You want to use explicit cursors to fetch and display all
the countries in a specific region. There are 19 rows in Mark for
the WF_WORLD_REGIONS table. You want to use a Review
different region each time the cursor is opened. How
(1) Points
many cursors should you declare?

19 cursors, all in the same PL/SQL block.


19 cursors in 19 PL/SQL blocks (one in each
block).
One cursor with a parameter in the WHERE
clause. (*)
None of the these.
20 cursors, in case an extra row is inserted into
WF_WORLD_REGIONS later.

Correct

14. Look at the following code:


Mark for
DECLARE Review
CURSOR emp_curs (p_dept_id (1) Points
employees.department_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id;
v_emp_rec emp_curs%ROWTYPE;
v_deptid NUMBER(4) := 50;
BEGIN
OPEN emp_curs( -- Point A --);
....

You want to open the cursor, passing value 50 to the


parameter. Which of the following are correct at Point
A?

All of these. (*)


v_deptid
100 / 2
50

Correct

15. You want to display all locations, and the departments


in each location. Examine the following code: Mark for
Review
DECLARE (1) Points
CURSOR loc_curs IS SELECT * FROM locations;
CURSOR dept_curs(p_loc_id NUMBER) IS
SELECT * FROM departments WHERE location_id =
p_loc_id;
BEGIN
FOR loc_rec IN loc_curs LOOP
DBMS_OUTPUT.PUT_LINE(loc_rec.city);
FOR dept_rec IN dept_curs(-- Point A --) LOOP
DBMS_OUTPUT.PUT_LINE(dept_rec.department_n
ame);
END LOOP;
END LOOP;
END;

What should you code at Point A?

location_id
LOOP ... END LOOP;
null
p_loc_id
loc_rec.location_id (*)

Correct
16. Which of
the Mark for Review
following (1) Points
is a good
reason to
use two
cursors in
a single
PL/SQL
block?
When two tables are related to each other (often by a foreign key) and
we want to produce a multilevel report using data from both tables. (*)
To allow rows to be locked as they are FETCHed.
It is the only way to declare a cursor with a parameter.
To speed up the execution of the PL/SQL block.
To allow one cursor to be opened twice at the same time.

Correct

Section 6
(Answer all questions in this section)

17. Consider the following code:


Mark for Review
DECLARE (1) Points
TYPE dept_info_type IS RECORD
(department_id departments.department_id%TYPE,
department_name departments.department_name%TYPE);
TYPE emp_dept_type IS RECORD
(first_name employees.first_name%TYPE,
last_name employees.last_name%TYPE),
dept_info dept_info_type);

v_dept_info_rec dept_info_type;
v_emp_dept_rec emp_dept_type;

How many fields can be addressed in v_dept_info_rec?

one
three
two (*)
four

Incorrect. Refer to Section 6 Lesson 1.

18. An INDEX BY TABLE must have a primary key.


Mark for Review
(1) Points

True (*)
False

Correct
Section 7
(Answer all questions in this section)

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

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

Use RAISE_APPLICATION_ERROR to raise an exception explicitly. (*)


Test for WHEN OTHERS in the exception section, because WHEN
OTHERS traps all exceptions.
Define an EXCEPTION variable and associate it with an Oracle Server
error number using PRAGMA EXCEPTION_INIT.
Test for WHEN VALUE_TOO_HIGH in the exception section.

Correct

20. Examine the following code. At Line A, you want to raise an exception if the
employee's manager_id is null. What kind of exception is this? Mark for Review
(1) Points
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 user-defined exception (*)


A NO_DATA_FOUND exception
A non-predefined Oracle server exception
A predefined Oracle Server exception
A constraint violation

Incorrect. Refer to Section 7 Lesson 2.


21. Which of
the Mark for Review
following (1) Points
are
examples
of
predefined
Oracle
Server
errors?
(Choose
three.)

(Choose all correct answers)

TOO_MANY_ROWS (*)
OTHERS
ZERO_DIVIDE (*)
E_INSERT_EXCEP
NO_DATA_FOUND (*)

Incorrect. Refer to Section 7 Lesson 2.

22. Which of the following are good practice guidelines for exception handling?
(Choose three.) Mark for Review
(1) Points

(Choose all correct answers)

Include a WHEN OTHERS handler as the first handler in the exception


section.
Handle specific named exceptions where possible, instead of relying on
WHEN OTHERS. (*)
Use an exception handler whenever there is any possibility of an error
occurring. (*)
Allow exceptions to propagate back to the calling environment.
Test your code with different combinations of data to see what potential
errors can happen. (*)

Incorrect. Refer to Section 7 Lesson 1.

23. Which of the following best describes a PL/SQL exception?


Mark for Review
(1) Points

An error occurs during execution which disrupts the normal operation of


the program. (*)
The programmer makes a spelling mistake while writiing the PL/SQL
code.
A DML statement does not modify any rows.
A user enters an invalid password while trying to log on to the database.

Correct

24. Examine the following code. Why does this exception handler not follow good
practice guidelines? Mark for Review
(1) Points
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;

employee_id 999 does not exist in the employees table.


The exception handler should COMMIT the transaction.
You should not use DBMS_OUTPUT.PUT_LINE in an exception handler.
The exception handler should test for the named exception
NO_DATA_FOUND. (*)

Correct

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


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

True
False (*)

Incorrect. Refer to Section 7 Lesson 3.


26. A user-
defined Mark for Review
exception (1) Points
must be
declared as
a variable of
data type
EXCEPTION.
True or
False?

TRUE (*)
FALSE

Correct
27. Department-id 99 does not exist. What will be displayed when the following
code is executed? Mark for Review
(1) Points
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;

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


ORA-01403: No Data Found
ORA-20201: Department does not exist (*)
None of these.

Correct

28. The following code does not violate any constraints and will not raise an
ORA-02292 error. What will happen when the code is executed? Mark for Review
(1) Points
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;

The code will fail because line 4 should read: PRAGMA


EXCEPTION_INIT(-2292, e_constraint_violation);
'Inner block message' will be displayed.
The code will fail because the exception is declared in the inner block
but is referenced in the outer block. (*)
'Outer block message' will be displayed.

Correct

29. No employees exist in department 75. What will be displayed when this code
is executed? Mark for Review
(1) Points
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;

A
D

(*)
A
None of these.
A
B
D
A
C
D

Incorrect. Refer to Section 7 Lesson 4.

Section 8
(Answer all questions in this section)

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

TRUE (*)
FALSE

Correct
31. You are
always able Mark for Review
to view and (1) Points
reload your
PL/SQL
stored
procedure's
code at a
later point
by clicking
on the
History
button in
the APEX
SQL
Commands
window.
True or
False?

True
False (*)

Correct

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

True (*)
False

Correct

33. The following procedure has been created:


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

myproc(40);
myproc(C => 25);
None of these. (*)
All of these.
myproc(10, B => 30, 50);

Correct

34. A procedure is invoked by this command:


Mark for Review
myproc('Smith',100,5000); (1) Points

What is the method of passing parameters used here?

A combination of positional and named


Positional (*)
None of these.
Named

Incorrect. Refer to Section 8 Lesson 3.

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


Mark for Review
(1) Points

They speed up the execution of the procedure.


They prevent the procedure from modifying data in the database.
They count the number of exceptions raised by the procedure.
They allow values to be passed between the calling environment and the
procedure. (*)

Correct
36. Procedure
TESTPROC Mark for
accepts Review
one
(1) Points
parameter
P1, whose
value is up
to 1000
characters
in length.
Which one
of the
following
declares
this
parameter
correctly?

CREATE PROCEDURE testproc


(p1 VARCHAR2)
IS
BEGIN ....

(*)
CREATE PROCEDURE testproc
(p1 VARCHAR2(100) )
IS
BEGIN ....
CREATE PROCEDURE testproc
IS
p1 VARCHAR2(100);
BEGIN ....
CREATE PROCEDURE testproc
DECLARE
p1 VARCHAR2(100);
BEGIN ....
CREATE PROCEDURE testproc
p1 VARCHAR2
IS
BEGIN ....

Correct

Section 9
(Answer all questions in this section)

37. Which dictionary view will list all the PL/SQL subprograms in your schema?
Mark for Review
(1) Points

user_procedures
user_dependencies
user_objects (*)
user_source
user_subprograms

Correct

38. Examine the following code:


Mark for Review
CREATE PROCEDURE parent (1) Points
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 next?

CHILD1 ends abruptly; PARENT handles the exception and then ends;
CHILD2 does not execute. (*)
PARENT handles the exception, and then CHILD1 continues to execute.
PARENT does not compile because you cannot use NULL; in an exception
handler.
CHILD1 ends abruptly, PARENT handles the exception, and then CHILD2
executes.
CHILD1 ends abruptly; PARENT also ends abruptly and returns an
unhandled exception.

Incorrect. Refer to Section 9 Lesson 4.


39. User SALLY's schema contains a NEWEMP table. Sally uses Invoker's rights to
create procedure GET_NEWEMP which includes the line: Mark for Review
(1) Points
SELECT ... FROM NEWEMP ... ;

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

The procedure will fail because Curly does not have SELECT privilege on
NEWEMP.
The procedure will execute successfully.
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

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

SELECT ... FROM EMPLOYEES ... ;

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

SYS.EMPLOYEES
DICK.EMPLOYEES
None of these.
HARRY.EMPLOYEES (*)

Correct
41. Which of
the Mark for
following Review
is a
(1) Points
benefit of
user-
defined
functions?
(Choose
3)

(Choose all correct answers)

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


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
efficiency. (*)
They can do the same job as built-in system functions such as UPPER and
ROUND.

Incorrect. Refer to Section 9 Lesson 2.

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


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

UPDATE employees SET salary = double_sal(salary);


SELECT * FROM employees WHERE double_sal(salary) > 20000;
SELECT * FROM employees ORDER BY double_sal(salary) DESC;
SELECT last_name, double_sal(salary) FROM employees;
None, they will all work (*)

Correct

43. Which of the following is NOT a benefit of user-defined functions?


Mark for Review
(1) Points

They can often be used inside SQL statements.


They can do the same job as built-in system functions such as UPPER and
ROUND. (*)
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.

Correct

44. Your schema contains two procedures named CHILD1 and CHILD2. You now
create a third procedure by executing: Mark for Review
(1) Points
CREATE OR REPLACE PROCEDURE parent IS
BEGIN
child1;
child2;
END;
You now want user JOE to be able to invoke PARENT. Which of the following
gives JOE the privileges he needs, but no unnecessary privileges?

GRANT EXECUTE ON * TO joe;


GRANT EXECUTE ON parent, child1, child2 TO joe;
GRANT EXECUTE ON parent TO joe WITH ADMIN OPTION;
GRANT EXECUTE ON parent TO joe;
GRANT EXECUTE ON child1 TO joe;
GRANT EXECUTE ON child2 TO joe;
GRANT EXECUTE ON parent TO joe;

(*)

Incorrect. Refer to Section 9 Lesson 5.

45. When a database object is first created, only its owner (creator) and the
Database Administrator are privileged to use it. True or False? Mark for Review
(1) Points

True (*)
False

Correct
46. To create a
function Mark for
successfully, Review
the
(1) Points
following
steps should
be
performed.

A Re-
execute the
code until it
compiles
correctly
B Write
the code
containing
the CREATE
or REPLACE
FUNCTION
followed by
the function
code
C Test the
function
from a SQL
statement
or an
anonymous
block
D If the
function
fails to
compile,
correct the
errors
E Load the
code into
Application
Express
F Execute
the code in
Application
Express

What is the
correct
order to
perform
these steps?

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

Correct

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


RETURN number Mark for Review
IS (1) Points
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?

GET_SAL is passed and V_SAL is returned.


SALARY is passed and P_ID is returned.
P_ID is passed and V_SAL is returned. (*)
EMPLOYEE_ID is passed and SALARY is returned.

Correct

48. Why will this function not compile correctly?


Mark for Review
CREATE FUNCTION bad_one (1) Points
IS BEGIN
RETURN NULL;
END bad_one;

You cannot RETURN a NULL.


The body of the function must contain at least one executable
statement (as well as RETURN).
You must code CREATE OR REPLACE, not CREATE.
You must have at least one IN parameter.
You must declare the type of the RETURN before the IS. (*)

Correct

49. You want to see the names of all the columns in a table in your schema. You
want to query the Dictionary instead of using the DESCRIBE command. Mark for Review
Which Dictionary view should you query? (1) Points

USER_TAB_COLS (*)
USER_TABLES
USER_OBJECTS
USER_COLUMNS

Incorrect. Refer to Section 9 Lesson 3.

50. Which of the following is NOT a benefit of the Data Dictionary?


Mark for Review
(1) Points

It will speed up the execution of SELECT statements in which the


WHERE clause column is not indexed. (*)
It allows us to remind ourselves of the names of our tables, in case we
have fogotten them.
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.
It allows us to check which system privileges have been granted to us.

Correct

Das könnte Ihnen auch gefallen