View Exhibit1 and examine the structure of the EMP table.
View Exhibit2 and examine the code created by the user SCOTT:
SCOTT grants the necessary privileges to green to access the EMP table and execute the package.
Examine the following sequence of activities:
SCOTT starts a session and issues the SQL>EXEC CURS_PKG.OPEN command.
SCOTT then issues the SQL>EXEC CURS_PKG.NEXT command.
green starts a session while SCOTT’s session is running and issues THE SQL>EXEC CURS_PKG.NEXT command.
SCOTT issues the SQI>>EXEC SCOTT.CURS_PKG.NEXT command.
The EMP table contains sequential EMPNOS from 100 through 108.
Which statement correctly describes the output?
A. SCOTT’s session shows the EMPNO 100, GREEN’S session shows an error, and SCOTT’s session shows an error.
B. SCOTT’s session shows the EMPNO 100, GREEN’S session shows EMPNO 100, and SCOTT’s session shows the EMPNO 101.
C. SCOTT’s session shows the EMPNO 100, GREEN’S session shows an error, and SCOTT’s session shows the second EMPNO 101.
D. SCOTT’s session shows the EMPNO 100, GREEN’S session shows EMPNO 101, and SCOTT’s session shows the second EMPNO 102.
I think correct answer is C.
Checked it from HR user session.
create or replace view emp (empno) as select employee_id from employees;
create or replace package curs_pkg is
procedure open;
procedure next(p_n number:=1);
procedure close;
end curs_pkg;
/
create or replace package body curs_pkg is
cursor cur_c is
select empno from emp;
procedure open is
begin
if not cur_c%isopen then
open cur_c;
end if;
end open;
procedure next(p_n number:=1) is
v_emp_id emp.empno%type;
begin
for count in 1..p_n loop
fetch cur_c into v_emp_id;
exit when cur_c%notfound;
dbms_output.put_line(‘Id: ‘ ||(v_emp_id));
end loop;
end next;
procedure close is
begin
if cur_c%isopen then
close cur_c;
end if;
end close;
end curs_pkg;
/
Following error is thrown in Green’s session because cursor wasn’t opened first before getting next record.
SQL> EXEC CURS_PKG.NEXT
BEGIN CURS_PKG.NEXT; END;
*
ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at “HR.CURS_PKG”, line 14
ORA-06512: at line 1