I would be calling procedure or function from java using JDBC.
In terms of best practice and performance, it is better to use a function which returns a SYS_REFCURSOR or use a procedure which returns a SYS_REFCURSOR.
Eg.
Procedure
create or replace procedure my_proc(p_deptno IN number,p_emp_no IN varchar2
, p_cursor OUT SYS_REFCURSOR)
is
begin
open p_cursor FOR
select *
from emp
where deptno = p_deptno and emp_number=p_emp_no;
end proc;
/
Function
CREATE OR REPLACE FUNCTION my_func (p_deptno IN number,p_emp_no IN varchar2)
RETURN SYS_REFCURSOR
AS
p_cursor SYS_REFCURSOR;
BEGIN
OPEN p_cursor FOR
select *
from emp
where deptno = p_deptno and emp_number=p_emp_no;
RETURN p_cursor;
END;
/
Which one of the above is a better option? Could someone provide some insight into this?
Any help is highly appreciable.
Thanks
From a performance standpoint, it doesn’t matter.
In general, if the intent of a PL/SQL block is to return something to the caller, it should be in a function. If the intent of a PL/SQL block is to do something (deletes, inserts, updates, etc.), it should be in a procedure. Since the intent of this code is to return something to the caller, it would be appropriate for it to be a function.