0% found this document useful (0 votes)
858 views17 pages

1 Final

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 17

Test: Semester 1 Final Exam

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

Section 5
(Answer all questions in this section)

1. A cursor has been declared as: Mark for Review


CURSOR c_curs (p_param VARCHAR2) IS
SELECT * FROM mytable (1) Points
WHERE mycolumn = p_param;
Which of the following will open the cursor successfully?

OPEN c_curs('ABC'); (*)


OPEN c_curs(p_param = "ABC");
p_param := 'ABC';
OPEN c_curs(p_param);
OPEN c_curs USING ("ABC");

Correct

2. There are 12 distinct JOB_IDs in the EMPLOYEES table. You need to write some PL/SQL Mark for Review
code to fetch and display all the employees with a specific JOB_ID. The chosen JOB_ID
can be different each time the code is executed. (1) Points
What is the best way to do this?

Write a single PL/SQL block which declares one cursor using a parameter for the
JOB_ID. (*)
Write a single PL/SQL block which uses a cursor to fetch all the employee rows, with
an IF statement to decide which of the fetched rows to display.
Write a single PL/SQL block which declares 12 cursors, one for each distinct value of
JOB_ID.
Write 12 separate PL/SQL blocks, each declaring a cursor with a different JOB_ID in
the WHERE clause.

Correct

3. Look at the following code: Mark for Review

DECLARE (1) Points


CURSOR emp_cursor IS
SELECT employee_id, last_name, salary FROM employees;
v_empcurs emp_cursor%ROWTYPE;

What is the data type of V_EMPCURS?

Record (*)
Cursor
Scalar
Row
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?

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

Correct

5. You have declared the following cursor: Mark for Review

CURSOR country_curs IS (1) Points


SELECT * FROM wf_countries
ORDER BY country_name;

There are over 200 rows in the WF_COUNTRIES table, but you want to fetch and display
only the first 25 rows.

How would you exit from the FETCH loop?

WHEN country_curs > 25 THEN EXIT; END IF;


EXIT WHEN ROWCOUNT > 25;
EXIT WHEN country_curs%FOUND(25);
EXIT WHEN country_curs%ROWCOUNT > 25; (*)

Correct
Section 5
(Answer all questions in this section)

6. 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_salary);
CLOSE emp_curs;
END;

All employees' salaries will be fetched and displayed.


The lowest salary value will be fetched and displayed.
The first employee's salary will be fetched and displayed.
The execution will fail and an error message will be displayed. (*)

Correct

7. You must make sure you have the same number of variables in your INTO statement Mark for Review
as you have in your SELECT list. True or False?
(1) Points

True (*)
False

Correct

8. What is wrong with the following code? Mark for Review

DECLARE (1) Points


CURSOR emp_curs IS SELECT last_name, salary FROM employees;
v_last_name employees.last_name%TYPE;
v_salary employees.salary%TYPE;
BEGIN
FETCH emp_curs INTO v_last_name, v_salary;
OPEN emp_curs;
FETCH emp_curs INTO v_last_name, v_salary;
CLOSE emp_curs;
END;

The first row is FETCHed before the cursor is OPENed. (*)


The cursor declaration does not include an INTO clause.
When FETCHing more than one row, you MUST use a loop.
The cursor declaration does not include a WHERE condition.

Correct

9. An explicit cursor must always be declared, opened, and closed by the PL/SQL Mark for Review
programmer. True or False?
(1) Points

TRUE
FALSE (*)
Correct

10. You want to produce a report which displays each department and (immediately after Mark for Review
each department) a list of employees who work in that department. You declare a
DEPARTMENTS cursor as: (1) Points

CURSOR dept_curs IS
SELECT * FROM departments
ORDER BY department_id;

How could you declare the EMPLOYEES cursor? (Choose two).

(Choose all correct answers)

CURSOR emp_curs IS SELECT * FROM employees;


CURSOR emp_curs (p_dept_id NUMBER) IS SELECT * FROM employees WHERE
department_id = p_dept_id; (*)
CURSOR emp_curs (p_dept_id departments.department_id%TYPE) IS SELECT *
FROM employees WHERE department_id = p_dept_id; (*)
CURSOR emp_curs IS SELECT * FROM employees ORDER BY department_id;
CURSOR emp_curs IS SELECT * FROM employees WHERE department_id =
departments.department_id;

Correct
Section 5
(Answer all questions in this section)

11. Which of the following is a good reason to declare and use multiple cursors in a single Mark for Review
PL/SQL block?
(1) Points

Multiple cursors can be opened many times, while a single cursor can be opened
only once.
Multiple cursors are the only way to use cursors with parameters.
Multiple cursors use less memory than a single cursor.
Multiple cursors allow us to fetch rows from two or more related tables without
using a JOIN. (*)
Multiple cursors improve performance. They are faster than using a single cursor.

Correct

12. If the rows you attempt to reserve using FOR UPDATE have already been locked by Mark for Review
another session and you use the NOWAIT option, what is the outcome?
(1) Points

Your rows will override the other user's lock and your block will execute
successfully.
The block executes successfully with no errors.
An Oracle server error occurs. (*)
The server will wait until the locks have been released by the other user.
Correct

13. User TOM has locked a row in the WORKERS table. Now, user DICK wants to open the Mark for Review
following cursor:
CURSOR c IS (1) Points

SELECT * FROM workers FOR UPDATE NOWAIT;

What will happen when DICK opens the cursor and tries to fetch rows?

TOM's session is rolled back. DICK's session successfully fetches rows from the
cursor.
The c%NOWAIT attribute is set to TRUE.
DICK's session waits indefinitely.
Both sessions wait for a few seconds; then the system breaks all locks and both
sessions raise an exception.
DICK's session immediately raises an exception. (*)

Correct

14. What is wrong with the following piece of code? Mark for Review

BEGIN (1) Points


FOR emp_record IN emp_cursor LOOP
DBMS_OUTPUT.PUT_LINE(emp_record.last_name);
END LOOP;
IF emp_record.last_name = 'Patel' THEN ...

You cannot reference EMP_RECORD outside the loop. (*)


It should read: DBMS_OUTPUT.PUT_LINE(emp_cursor.last_name);
EMP_RECORD has not been explicitly declared.
Nothing is wrong; the code will execute correctly.
The cursor has not been OPENed.

Correct

15. 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_LINE( --Point A -- );
END LOOP;
END;

To display the salary of an employee, what code should you write at Point A?

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

Correct
Section 5
(Answer all questions in this section)

16. A cursor FOR loop using a subquery can shorten code length when compared to an Mark for Review
explicit cursor declaration. True or False?
(1) Points

True (*)
False

Correct

Section 6
(Answer all questions in this section)

17. An INDEX BY TABLE primary key cannot be negative. Mark for Review
(1) Points

True
False (*)

Correct

18. The following code declares a PL/SQL record with the same structure as a row of the Mark for Review
departments table. True or False?
(1) Points
DECLARE
v_dept_rec departments%ROWTYPE;
...

True (*)
False

Correct
Section 7
(Answer all questions in this section)

19. While a PL/SQL block is executing, more than one exception can occur at the same Mark for Review
time. True or False?
(1) Points

TRUE
FALSE (*)

Correct

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

(Choose all correct answers)

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

Correct

Section 7
(Answer all questions in this section)

21. Which of the following best describes a PL/SQL exception? Mark for Review
(1) Points

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

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

None of these.
A
A
C
D
A
B
D
A
D

(*)

Correct

23. What will be displayed when the following code is executed? Mark for Review

<<outer>> (1) Points


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;
30
200
40
10
20 (*)

Correct

24. Which of the following best describes a predefined Oracle Server error? Mark for Review
(1) Points

Has a standard Oracle error number and a standard name which can be
referenced in the EXCEPTION section (*)
Is not raised automatically but must be declared and raised explicitly by the
PL/SQL programmer
Is associated with an Oracle error number using PRAGMA EXCEPTION_INIT
Has a standard Oracle error number but must be named by the PL/SQL
programmer

Correct

25. Examine the following code. At Line A, you want to raise an exception if the Mark for Review
employee's manager_id is null. What kind of exception is this?
(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 NO_DATA_FOUND exception
A constraint violation
A predefined Oracle Server exception
A non-predefined Oracle server exception
A user-defined exception (*)

Correct
Section 7
(Answer all questions in this section)

26. Which kinds of exceptions are raised implicitly (i.e., automatically)? (Choose two.) Mark for Review
(1) Points
(Choose all correct answers)

All errors
Predefined Oracle Server errors such as NO_DATA_FOUND (*)
Non-predefined Oracle Server errors such as ORA-01400 (*)
User-defined errors

Correct

27. No employees are in department_id 99. What output will be displayed when the Mark for Review
following code is executed?
(1) Points
DECLARE
v_count NUMBER;
BEGIN
SELECT COUNT(*) INTO v_count
FROM employees WHERE department_id = 99;
IF v_count = 0 THEN
RAISE NO_DATA_FOUND;
DBMS_OUTPUT.PUT_LINE('No employees found');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Department 99 is empty');
END;

Department 99 is empty (*)


The block will fail because you cannot explicitly RAISE a predefined Oracle Server
error such as NO_DATA_FOUND
No employees found
No employees found Department 99 is empty

Correct

28. Which of the following will successfully return a user-defined error message? Mark for Review
(1) Points

RAISE_APPLICATION_ERROR(-29001,'Error Raised');
RAISE_APPLICATION_ERROR('Error Raised',-22001);
RAISE_APPLICATION_ERROR('Error Raised',-20257);
RAISE_APPLICATION_ERROR(-20257,'Error raised'); (*)

Correct

29. User-defined exceptions must be declared explicitly by the programmer, but then are Mark for Review
raised automatically by the Oracle Server. True or False?
(1) Points
TRUE
FALSE (*)

Correct

Section 8
(Answer all questions in this section)

30. Suppose you set up a parameter with an explicit IN mode. What is true about that Mark for Review
parameter?
(1) Points

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

Correct
Section 8
(Answer all questions in this section)

31. Procedure SOMEPROC has five parameters named A, B, C, D, E in that order. The Mark for Review
procedure was called as follows:
(1) Points
SOMEPROC(10,20,30,D=>50,E=>60);

How was parameter B referenced?

Named
Positional (*)
A combination of named and defaulted
A combination of positionally and named
Defaulted

Incorrect. Refer to Section 8 Lesson 3.

32. Why will the following procedure fail? Mark for Review

CREATE OR REPLACE PROCEDURE mainproc (1) Points


...
IS
PROCEDURE subproc (...) IS BEGIN
...
BEGIN
...
subproc (...);
...
END;

Procedure main proc must use the keyword AS not IS


Procedure subproc does not need the keyword BEGIN
Procedure subproc does not have an END; statement (*)
Procedure mainproc does not need the keyword BEGIN

Correct

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

True
False (*)

Correct

34. A PL/SQL stored procedure can accept one or more input parameters and can return Mark for Review
one or more output values to the calling environment. True or False?
(1) Points

TRUE (*)
FALSE

Correct

35. What is the correct syntax to create procedure MYPROC that accepts two number Mark for Review
parameters X and Y?
(1) Points

CREATE PROCEDURE myproc (x NUMBER, y NUMBER) IS ... (*)


CREATE PROCEDURE myproc IS (x NUMBER, y NUMBER) ...
CREATE PROCEDURE IS myproc (x NUMBER, y NUMBER) …
CREATE PROCEDURE (x NUMBER, y NUMBER) myproc IS ...

Correct
Section 8
(Answer all questions in this section)

36. Which of the following is NOT correct coding for a procedure parameter? Mark for Review
(1) Points
(p_param IN VARCHAR2)
(p_param VARCHAR2)
(p_param VARCHAR2(50)) (*)
(p_param IN NUMBER)
(p_param employees.last_name%TYPE)

Correct

Section 9
(Answer all questions in this section)

37. Function DOUBLE_SAL has been created as follows: CREATE OR REPLACE FUNCTION Mark for Review
double_sal (p_salary IN employees.salary%TYPE) RETURN NUMBER IS BEGIN
RETURN(p_salary * 2); END; Which of the following calls to DOUBLE_SAL will NOT (1) Points
work?

SELECT * FROM employees ORDER BY double_sal(salary) DESC;


SELECT * FROM employees WHERE double_sal(salary) > 20000;
SELECT last_name, double_sal(salary) FROM employees;
UPDATE employees SET salary = double_sal(salary);
None, they will all work (*)

Correct

38. The following function has been created: Mark for Review

CREATE OR REPLACE FUNCTION upd_dept (1) Points


(p_dept_id IN departments.department_id%TYPE)
RETURN NUMBER IS
BEGIN
UPDATE departments SET department_name = 'Accounting'
WHERE department_id = p_dept_id;
RETURN p_dept_id;
END;

Which of the following will execute successfully?

DELETE FROM departments


WHERE department_id = upd_dept(department_id);
SELECT upd_dept(department_id)
FROM employees;
SELECT upd_dept(80)
FROM dual;
DELETE FROM employees
WHERE department_id = upd_dept(80);

(*)
Correct

39. The function avg_ann_sal returns the average annual salary for a particular Mark for Review
department. The example below is a valid use of this function. True or False?
(1) Points
SELECT first_name, last_name
FROM employees
WHERE avg_ann_sal(20) > 15000;

True (*)
False

Correct

40. User DIANE owns a DEPARTMENTS table. User JOEL needs to update the location_id Mark for Review
column of Diane's table, but no other columns. Which SQL statement should Diane
execute to allow this? (1) Points

GRANT UPDATE ON departments.location_id TO joel;


GRANT UPDATE ON location_id OF departments TO joel;
GRANT UPDATE(location_id) ON departments TO joel; (*)
GRANT UPDATE ON departments TO joel;
GRANT UPDATE ON departments(location_id) TO joel;

Correct
Section 9
(Answer all questions in this section)

41. JOE's schema contains a COUNTRIES table. The following commands are executed by Mark for Review
JOE and TOM:
(JOE): GRANT SELECT ON countries TO tom WITH GRANT OPTION; (1) Points
(TOM): GRANT SELECT on joe.countries TO dick WITH GRANT OPTION;

Now, JOE executes:


REVOKE SELECT ON countries FROM tom;
What happens to the grant to DICK?

Nothing. DICK's privilege is preserved even though TOM lost his privilege.
DICK also loses his SELECT privilege. (*)
The REVOKE statement fails because JOE must remove the SELECT privilege from
both users at the same time.
The REVOKE statement fails because only the Database Administrator (not JOE)
can revoke privileges.

Incorrect. Refer to Section 9 Lesson 5.


42. You want to display the names of all tables in your schema, but you have forgotten Mark for Review
which Dictionary view to query. Which of the following will remind you of the name of
the correct Dictionary view? (1) Points

HELP DICTIONARY
SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'user%table%';
SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'USER%TAB%';

(*)
SELECT *
FROM USER_OBJECTS
WHERE table_name LIKE '%TABLE%';
SELECT *
FROM DICTIONARY
WHERE table_name LIKE 'DBA%TABLE%';

Correct

43. User JOHN wants to see the names of all the tables in his schema. He does NOT want Mark for Review
to see the names of any tables in other users' schemas. Which Dictionary view should
he query? (1) Points

USER_TABLES (*)
DICTIONARY
ALL_TABLES
JOHN_TABLES
DBA_TABLES

Incorrect. Refer to Section 9 Lesson 3.

44. Which of the following best describes a stored function? Mark for Review
(1) Points

A subprogram that executes automatically when a DML statement is executed on


a table
A subprogram that has no OUT or IN OUT parameters
A subprogram which invokes another subprogram
A subprogram that must return exactly one value (*)
A subprogram that must have at least one IN parameter

Correct

45. Which of the following is a difference between a procedure and a function? Mark for Review
(1) Points
A procedure can have default values for parameters, while a function cannot.
A function must return a value; a procedure may or may not. (*)
A function cannot be used within a SQL statement; a procedure can be used
within SQL.
Functions cannot be nested; procedures can be nested to at least 8 levels.
An explicit cursor can be declared in a procedure, but not in a function.

Correct
Section 9
(Answer all questions in this section)

46. You have created a function called GET_COUNTRY_NAME which accepts a country_id Mark for Review
as an IN parameter and returns the name of the country. Which one of the following
calls to the function will NOT work? (1) Points

v_name := get_country_name(100);
BEGIN get_country_name(100, v_name); END; (*)
DBMS_OUTPUT.PUT_LINE(get_country_name(100));
SELECT get_country_name(100) FROM dual;

Correct

47. Procedure ins_emp accepts an employee_id as an IN parameter and attempts to insert Mark for Review
a row with that employee_id into the EMPLOYEES table. Ins_emp does not contain an
exception section. A second procedure is created as follows: (1) Points

CREATE OR REPLACE PROCEDURE call_ins_emp IS


BEGIN
ins_emp(99); -- this employee does not exist
ins_emp(100); -- this employee already exists
ins_emp(999); -- this employee does not exist
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An exception occurred');
END;

When call_ins_emp is executed, (assuming Auto Commit is turned on), which rows will
be inserted into the EMPLOYEES table?

999 only
All three rows will be inserted
99 only (*)
99 and 999
No rows will be inserted

Correct
48. You want to see the names, modes, and data types of the formal parameters of Mark for Review
function MY_FUNC in your schema. How can you do this? (Choose two)
(1) Points

(Choose all correct answers)

Query USER_SOURCE (*)


Query USER_PARAMETERS
DESCRIBE my_func; (*)
Query USER_FUNCTIONS
SHOW PARAMETER my_func;

Correct

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

SELECT ... FROM EMPLOYEES ... ;

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

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

Correct

50. Which statement is true regarding the following subprogram? Mark for Review

PROCEDURE at_proc IS (1) Points


PRAGMA AUTONOMOUS_TRANSACTION;
dept_id NUMBER := 90;
BEGIN
UPDATE ...
INSERT ...
END at_proc;

The subprogram's success is independent of the calling program. (*)


The subprogram will fail because the RETURN is not specified.
The subprogram cannot do a COMMIT.
The subprogram's success depends on the calling program.

Incorrect. Refer to Section 9 Lesson 6.

You might also like