В вашем коде слишком много глупых ошибок, я их исправил.Внимательно наблюдайте за изменениями.
Пакет
CREATE OR REPLACE PACKAGE cursor_state IS
CURSOR emp_curs IS
SELECT e.first_name, e.last_name, d.department_name, e.salary
FROM employees e join departments d
ON e.department_id = d.department_id;
PROCEDURE open_curs;
FUNCTION fetch_rows(n NUMBER DEFAULT 1) RETURN BOOLEAN;
PROCEDURE close_curs;
END cursor_state;
/
Тело пакета
CREATE OR REPLACE PACKAGE BODY cursor_state IS
PROCEDURE open_curs IS
BEGIN
IF NOT emp_curs%isopen THEN
OPEN emp_curs;
END IF;
END open_curs;
FUNCTION fetch_rows(n NUMBER DEFAULT 1) RETURN BOOLEAN IS
emp_first employees.first_name%TYPE;
emp_last employees.last_name%TYPE;
emp_dept departments.department_name%TYPE;
emp_salary employees.salary%TYPE;
BEGIN
FOR count IN 1 .. n LOOP
FETCH emp_curs INTO
emp_first,emp_last,emp_dept,emp_salary;
EXIT WHEN emp_curs%notfound;
dbms_output.put_line(emp_first||','
||emp_last
||','
||emp_dept
||','
||emp_salary);
END LOOP;
RETURN emp_curs%found;
END fetch_rows;
PROCEDURE close_curs IS
BEGIN
IF emp_curs%isopen THEN
CLOSE emp_curs;
END IF;
END close_curs;
END cursor_state;
/
Выполнение
SET SERVEROUTPUT ON
DECLARE
x BOOLEAN;
BEGIN
cursor_state.open_curs;
x:=cursor_state.fetch_rows(5);
cursor_state.close_curs;
END;
/
Результат
Jennifer,Whalen,Administration,4400
Michael,Hartstein,Marketing,13000
Pat,Fay,Marketing,6000
Den,Raphaely,Purchasing,11000
Karen,Colmenares,Purchasing,2500
PL/SQL procedure successfully completed.