1 1
1 1
1 1
DECLARE
v_outer_count NUMBER := 1;
v_inner_count NUMBER := 1;
BEGIN
LOOP
LOOP
v_inner_count := v_inner_count + 1;
EXIT WHEN v_inner_count > 5; -- Line A
END LOOP;
v_outer_count := v_outer_count + 1;
EXIT WHEN v_outer_count > 3;
END LOOP;
END;
(1) Points
Both loops are exited and the block's execution is terminated.
The inner loop is exited but the outer loop continues execution. (*)
The outer loop is exited but the inner loop continues execution.
<<big_loop>>
WHILE condition_1 LOOP
<<small_loop>>
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE(i);
-- Line A
END LOOP;
END LOOP;
(1) Points
IF v_number = 6 THEN EXIT;
False (*)
Correct
4. What kinds of loops can be nested? (1) Points
BASIC loops
WHILE loops
FOR loops
Correct
5. What will happen when the following code is executed?
BEGIN
FOR i in 1 ..3 LOOP
DBMS_OUTPUT.PUT_LINE (i);
i := i + 1;
END LOOP;
END;
(1) Points
It will display 1, 2, 3.
It will display 2, 3, 4.
It will result in an error because you cannot modify the counter in a FOR loop. (*)
It will result in an error because the counter was not explicitly declared.
(1) Points
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i + 1;
END LOOP;
END;
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
i := i + 1;
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
END;
(*)
DECLARE
i PLS_INTEGER := 0;
BEGIN
WHILE i<3 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
i := i+ 1;
END;
Correct
7. Examine the following code:
DECLARE
v_bool BOOLEAN := FALSE;
v_counter NUMBER(4) := 0;
BEGIN
... Line A
...
END;
Which of the following is NOT valid at line A?
(1) Points
WHILE NOT v_boolean LOOP
False
Correct
9. When using a counter to control a FOR loop, which of the following is true ? (1)
Points
You must have exactly one counter but it is implicitly declared. (*)
You must have exactly one counter and you must explicitly declare it.
You can have multiple counters, but you need at least one.
You don't need a counter; you can test for anything (for example, whether a BOOLEAN is
TRUE or FALSE).
DECLARE
v_age NUMBER:= 18;
v_answer VARCHAR2(10);
BEGIN
v_answer :=
CASE
WHEN v_age < 25 THEN 'Young'
WHEN v_age = 18 THEN 'Exactly 18'
ELSE 'Older'
END CASE;
END;
(1) Points
Exactly 18
Young (*)
Null
Older
DECLARE
v_salary NUMBER(6,2) := NULL;
v_sal_desc VARCHAR2(10);
BEGIN
CASE
WHEN v_salary < 10000 THEN v_sal_desc := 'Low Paid';
WHEN v_salary >= 10000 THEN v_sal_desc := 'High Paid';
END CASE;
END;
(1) Points
High Paid
Low Paid
Null (*)
Correct
12. Which of the following is NOT a characteristic of a CASE statement? (1)
Points
It ends with END CASE;
DECLARE
v_grade CHAR(1);
BEGIN
CASE v_grade
(1) Points
WHEN 'A' THEN (*)
IF 'A' THEN
DECLARE
v_grade CHAR(1);
v_result VARCHAR2(10);
BEGIN
v_result :=
CASE v_grade
(1) Points
WHEN v_grade = 'A' THEN 'Very Good'
They must match the same number as the number of ELSE statements.
Array structures
Memory structures
Cursor structures
Loops (*)
CASE expressions
CASE statements
Correct
18. Examine the following code:
DECLARE
v_salary NUMBER(6);
v_constant NUMBER(6) := 15000;
v_result VARCHAR(6) := 'MIDDLE';
BEGIN
IF v_salary != v_constant THEN
v_result := 'HIGH';
ELSE
v_result := 'LOW';
END IF;
END;
(1) Points
HIGH
LOW (*)
MIDDLE
Null
DECLARE
a VARCHAR2(6) := NULL;
b VARCHAR2(6) := NULL;
BEGIN
IF a = b THEN
DBMS_OUTPUT.PUT_LINE('EQUAL');
ELSIF a != b THEN
DBMS_OUTPUT.PUT_LINE('UNEQUAL');
ELSE
DBMS_OUTPUT.PUT_LINE('OTHER');
END IF;
END;
(1) Points
UNEQUAL
EQUAL
OTHER (*)
IF condition
THEN statement1
ELSE statement 2;
END IF;
IF condition;
THEN statement1;
ELSE statement2;
END IF;
(*)
'won'
'lost' (*)
False
(1) Points
FOR loop
IF-THEN loop
WHILE loop
CASE loop
Correct
23. Examine the following block:
DECLARE
v_counter PLS_INTEGER := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(v_counter);
v_counter := v_counter + 1;
EXIT WHEN v_counter = 5;
END LOOP;
END;
(1) Points
5
4 (*)
Correct
24. Which one of these is NOT a kind of loop? (1) Points
ASCENDING loop (*)
FOR loop
Basic loop
WHILE loop
Correct
25. The EXIT statement can be located anywhere inside a basic loop. True or False? (1)
Points
True (*)
False
(1) Points
5
Correct
Section 5 27. Examine the following code. To display the salary of an
employee, what must be coded at Point A?
DECLARE
CURSOR emp_curs IS SELECT * FROM employees;
BEGIN
FOR emp_rec IN emp_curs LOOP
DBMS_OUTPUT.PUT_LINE( -- what goes here ? );
END LOOP;
END;
(1) Points
salary
emp_curs.salary
emp_rec.salary (*)
employees.salary
emp_rec.salary IN emp_curs
Correct
28. What is wrong with the following code?
BEGIN
FOR emp_rec IN
(SELECT * FROM employees WHERE ROWNUM < 10
FOR UPDATE NOWAIT) LOOP
DBMS_OUTPUT.PUT_LINE(emp_rec%ROWCOUNT || emp_rec.last_name):
END LOOP;
END;
(1) Points
You cannot use FOR UPDATE NOWAIT with a cursor FOR loop using a subquery.
You cannot reference %ROWCOUNT with a cursor FOR loop using a subquery. (*)
DECLARE
CURSOR dept_curs IS SELECT * FROM departments;
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;
(1) Points
The cursor DEPT_CURS has not been opened.
The implicitly declared record DEPT_REC cannot be referenced outside the cursor FOR
loop. (*)
Correct
30. Examine the following declaration of a cursor with a parameter. What should be
coded at Point A?
DECLARE
CURSOR emp_curs(-- Point A --) IS
SELECT * FROM employees
WHERE job_id = p_job_id;
(1) Points
p_job_id
ST_CLERK'
p_job_id VARCHAR2(25)
job_id VARCHAR2
Correct
31. A cursor has been declared as:
(1) Points
OPEN c_curs(p_param = ABC);
p_param := 'ABC';
OPEN c_curs(p_param);
DECLARE
CURSOR emp_curs IS
SELECT * FROM employees
FOR -- Point A
(1) Points
UPDATE;
UPDATE OF salary;
UPDATE NOWAIT;
Correct
33. A cursor is declared as:
After opening the cursor and fetching some rows, you want to delete the most recently fetched
row. Which of the following will do this successfully?
(1) Points
DELETE FROM c WHERE CURRENT OF c;
Correct
34. Consider the following cursor:
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?
(1) Points
The whole EMPLOYEES table is locked.
In the EMPLOYEES table, only the 'Smith' rows are locked. Nothing in the
DEPARTMENTS 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. (*)
Nothing is locked because the cursor was not declared with NOWAIT.
DECLARE
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?
(1) Points
v_emp_rec.last_name (*)
v_emp_rec(last_name)
v_emp_rec
last_name
Correct
36. The following cursor has been declared:
CURSOR emp_curs IS
SELECT first_name, last_name, job_id, salary
FROM employees;
Which of the following correctly declares a composite record with the same structure as the
cursor?
(1) Points
emp_rec emp_rec%ROWTYPE;
emp_rec emp_curs%TYPE;
emp_rec cursor%ROWTYPE;
Correct
37. The employees table contains 11 columns. The following block declares a cursor
and a record based on the cursor:
DECLARE
CURSOR emp_curs IS
SELECT * FROM employees;
v_emp_rec emp_curs%ROWTYPE;
A twelfth column is now added to the employees table. Which of the following statements is
true?
(1) Points
The declaration of emp_rec must be changed to add an extra field.
The block will still work correctly without any changes to the PL/SQL code. (*)
An extra scalar variable must be declared to correspond to the twelfth table column.
%NOTFOUND
%FOUND
%ROWCOUNT
Correct
39. Which of these statements about implicit cursors is NOT true? (1) Points
They are declared automatically by Oracle for single-row SELECT statements.
CURSOR emp_curs IS
SELECT salary
FROM employees
WHERE last_name LIKE 'S%';
CURSOR emp_dept_curs IS
SELECT e.salary, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id;
CURSOR emp_curs IS
SELECT salary INTO v_salary
FROM employees;
(*)
Correct
41. An explicit cursor must always be declared, opened and closed by the PL/SQL programmer.
True or False? (1) Points
True
False (*)
Correct
42. After a cursor has been closed, it can be opened again in the same PL/SQL block.
True or False? (1) Points
True (*)
False
Correct
43. Which of these constructs can be used to fetch multiple rows from a cursor's active
set? (1) Points
A CASE statement
A basic loop which includes FETCH and EXIT WHEN statements (*)
Correct
44. What will happen when the following code is executed?
DECLARE
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;
(1) Points
The first employee's salary will be fetched and displayed.
The execution will fail and an error message will be displayed. (*)
Correct
45. What will happen when the following code is executed?
(1) Points
The block will fail and an INVALID_CURSOR exception will be raised. (*)
Correct
46. The employees table contains 20 rows. What will happen when the following code
is executed?
DECLARE
CURSOR emp_curs IS
SELECT job_id FROM employees;
v_job_id employees.job_id%TYPE;
BEGIN
OPEN emp_curs;
LOOP
FETCH emp_curs INTO v_job_id;
DBMS_OUTPUT.PUT_LINE(v_job_id);
EXIT WHEN emp_curs%NOTFOUND;
END LOOP;
CLOSE emp_curs;
END;
(1) Points
20 job_ids will be displayed.
21 rows of output will be displayed; the first job_id will be displayed twice.
21 rows of output will be displayed; the last job_id will be displayed twice. (*)
Correct
47. An implicit cursor can be used for a multiple-row SELECT statement. True or
False? (1) Points
True
False (*)
Correct
Section 5 Continued 48. What is wrong with the following code?
DECLARE
CURSOR emp_curs(p_dept_id NUMBER) IS
SELECT * FROM employees WHERE department_id = p_dept_id;
BEGIN
FOR dept_rec IN (SELECT * FROM departments) LOOP
DBMS_OUTPUT.PUT_LINE(dept_rec.department_name);
FOR emp_rec IN emp_curs(dept_rec.department_id) LOOP
DBMS_OUTPUT.PUT_LINE(emp_rec.last_name);
END LOOP;
END LOOP;
END;
(1) Points
The DEPARTMENTS cursor must be declared with a parameter.
Nothing is wrong. The block will execute successfully and display all departments and the
employees in those departments. (*)
Correct
49. You want to display all locations, and the departments in each location. Examine the
following code:
DECLARE
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_name);
END LOOP;
END LOOP;
END;
(1) Points
p_loc_id
location_id
null
loc_rec.location_id (*)
Correct
50. Which of the following is a good reason to declare and use multiple cursors in a
single PL/SQL block? (1) Points
Multiple cursors improve performance. They are faster than using a single cursor.
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 are the only way to use cursors with parameters.
Multiple cursors can be opened many times, while a single cursor can be opened only once.
Correct