I need to print the result set or all rows fetched about the query:
CREATE OR REPLACE
PROCEDURE get_emp_rs
(p_deptno IN hr.employees.department_id%TYPE,
p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
SELECT first_name,
salary,
department_id
FROM hr.employees
WHERE department_id = p_deptno
ORDER BY first_name;
END get_emp_rs;
/
declare
v varchar2(4000);
z varchar2(4000);
begin
z:=get_emp_rs( 90, v);
dbms_output.put_line(z);
end;
/
ORA-06550: line 5, column 6:
PLS-00222: no function with name ‘GET_EMP_RS’ exists in this scope
ORA-06550: line 5, column 3:
Is it possible to close the cursor somewhere in the procedure?
close p_recordset;
CREATE OR REPLACE
PROCEDURE get_emp_rs
(p_deptno IN hr.employees.department_id%TYPE,
p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
SELECT first_name,
salary,
department_id
FROM hr.employees
WHERE department_id = 90
ORDER BY first_name;
close p_recordset; – maybe I’m crazy
END get_emp_rs;
You won’t be able to fetch the data once the cursor is close. If you want the cursor to open and close in the same procedure, you can move the code to output data into the same procedure. Or, you will need some other types of storage (e.g. a table) to keep the data for later access.