CREATE OR REPLACE PACKAGE my_curs AS
PROCEDURE cursorauf;
PROCEDURE ausgabe (
zeilenanzahl NUMBER
);
PROCEDURE cursorzu;
END;
/
CREATE OR REPLACE PACKAGE BODY my_curs AS
CURSOR c_emp IS
SELECT
*
FROM
emp;
rec_emp c_emp%rowtype;
PROCEDURE cursorauf IS
BEGIN
OPEN c_emp;
FETCH c_emp INTO rec_emp;
dbms_output.put_line('Name:' || rec_emp.ename);
dbms_output.new_line;
END cursorauf;
PROCEDURE ausgabe (
zeilenanzahl NUMBER
) IS
BEGIN
IF NOT c_emp%isopen THEN
OPEN c_emp;
END IF;
FOR i IN 1..zeilenanzahl LOOP
FETCH c_emp INTO rec_emp;
EXIT WHEN c_emp%notfound OR c_emp%notfound IS NULL;
dbms_output.put_line('Name:' || rec_emp.ename);
END LOOP;
END ausgabe;
PROCEDURE cursorzu IS
BEGIN
CLOSE c_emp;
END cursorzu;
END my_curs;
/
exec my_curs.cursorauf;
exec my_curs.ausgabe(5);
exec my_curs.cursorzu;