|
|||
|
|||
|
|||
|
|||
|
|||
2. The following cursor has been declared:
CURSOR
emp_curs
(p_dept_id employees.department_id%TYPE,
p_job_id employees.job_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id
AND job_id = p_job_id;
(p_dept_id employees.department_id%TYPE,
p_job_id employees.job_id%TYPE) IS
SELECT * FROM employees
WHERE department_id = p_dept_id
AND job_id = p_job_id;
Which of the following will correctly open the
cursor?
|
||
|
||
|
||
|
||
|
3. Place the
following statements in the correct sequence:
Place the
following statements in the correct sequence:
|
|||
|
|||
|
|||
|
|||
|
|||
4. An implicit cursor can be used for a multiple-row SELECT statement. True or
False?
|
||
|
5. An explicit cursor must always be declared, opened, and closed by
the PL/SQL programmer. True or False?
| ||||||||
6. Which of these is NOT a valid cursor declaration
|
||
|
||
|
||
|
7. Look at the following code
DECLARE
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?
| |||
|
|||
|
|||
|
|||
|
|||
8. Examine the
following code:
DECLARE
CURSOR country_curs IS
SELECT country_id, country_name
FROM wf_countries
ORDER BY country_name;
v_country country_curs%ROWTYPE;
BEGIN
OPEN country_curs;
LOOP
FETCH country_curs INTO v_country;
EXIT WHEN country_curs%NOTFOUND;
------- Line A
END LOOP;
CLOSE country_curs;
END;
You want to display the id and name of each FETCHed
country. What would you code at Line A?
CURSOR country_curs IS
SELECT country_id, country_name
FROM wf_countries
ORDER BY country_name;
v_country country_curs%ROWTYPE;
BEGIN
OPEN country_curs;
LOOP
FETCH country_curs INTO v_country;
EXIT WHEN country_curs%NOTFOUND;
------- Line A
END LOOP;
CLOSE country_curs;
END;
|
||
|
||
|
||
|
9. User TOM has
locked a row in the WORKERS table. Now, user DICK wants to open the following
cursor:
CURSOR c IS
CURSOR c IS
SELECT *
FROM workers FOR UPDATE NOWAIT;
What will happen when DICK opens the cursor and
tries to fetch rows?
|
||
|
||
|
||
|
||
|
10. You want to fetch rows from the EMPLOYEES table. You want to lock the
fetched rows to prevent other users from updating them. You declare the
following cursor: CURSOR emp_curs IS
SELECT
employee_id, last_name, salary
FROM employees
-- Line A -- ; What should you code at Line A?
FROM employees
-- Line A -- ; What should you code at Line A?
|
|||
|
|||
|
|||
|
|||
11. User MARY has locked a row of the EMPLOYEES table. Now, user SAEED tries to
open the following cursor:
CURSOR c IS
SELECT * FROM employees
FOR UPDATE WAIT 5;
What will happen when SAEED's session tries to
fetch the row that MARY has locked?
SELECT * FROM employees
FOR UPDATE WAIT 5;
|
||
|
||
|
||
|
||
|
12. 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;
What should you code at Point A?
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;
What should you code at Point A?
|
||
|
||
|
||
|
||
|
13. Examine the
following code:
DECLARE
CURSOR region_cur IS
SELECT * FROM wf_world_regions;
v_region_rec region_cur%ROWTYPE;
CURSOR country_cur (p_region_id NUMBER) IS
SELECT * FROM wf_countries
WHERE region_id = p_region_id;
v_country_rec country_cur%ROWTYPE;
BEGIN
OPEN region_cur;
LOOP
FETCH region_cur INTO v_region_rec;
EXIT WHEN region_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE
(v_region_rec.region_name);
-- Line A --
LOOP
FETCH country_cur INTO v_country_rec;
EXIT WHEN country_cur%NOTFOUND;
......
CURSOR region_cur IS
SELECT * FROM wf_world_regions;
v_region_rec region_cur%ROWTYPE;
CURSOR country_cur (p_region_id NUMBER) IS
SELECT * FROM wf_countries
WHERE region_id = p_region_id;
v_country_rec country_cur%ROWTYPE;
BEGIN
OPEN region_cur;
LOOP
FETCH region_cur INTO v_region_rec;
EXIT WHEN region_cur%NOTFOUND;
DBMS_OUTPUT.PUT_LINE
(v_region_rec.region_name);
-- Line A --
LOOP
FETCH country_cur INTO v_country_rec;
EXIT WHEN country_cur%NOTFOUND;
......
What
would you code at Line A?
|
||
|
||
|
||
|
||
|
14. When using a cursor FOR loop, OPEN, CLOSE, and FETCH statements should not
be explicitly coded. True or False?
|
||
|
15. The
following code fragment shows a cursor FOR loop:
FOR emp_record IN emp_cursor LOOP ......
Which of the following do NOT need to be coded explicitly? (Choose three.)
(Choose
all correct answers)
|
||
|
||
|
||
|
||
|
Social Plugin