What is a ref cursor and how is the data fetched..
this is my function :
create or replace function get_dept(p_deptno in number) return sys_refcursor is
open v_rc for select empno, ename, mgr, sal from emp where deptno = p_deptno;
i couldn't print the empno,ename,mgr,sal..so how could i print these things ..
Refcursor is a a well documented concept. Please read Performing SQL Operations from PL/SQL.
What do you exactly mean by print. Where do you want to display the output? For instance if your want to display the output in SQL Plus then you can use SQL Plus command PRINT. So basically it depends on the client tool that you are using.
v_rc := get_dept_emps(10); -- This returns an open cursor
fetch v_rc into v_empno, v_ename, v_mgr, v_sal;
exit when v_rc%NOTFOUND; -- Exit the loop when we've run out of data
dbms_output.put_line('Row: '||v_rc%ROWCOUNT||' # '||v_empno||','||v_ename||','||v_mgr||','||v_sal);
See my response above.. its has dbms_output.put_line to print the ref cursor. You first need to fetch the column from Ref cousor into local variable and then print them.
No, DBMS_OUTPUT does NOT print anything. It is server code. It is incapable of writing data to the display of an user. Or return data to a user session.
Using DBMS_OUTPUT for anything else but primitive debugging on the server, is almost always wrong.