Home » SQL & PL/SQL » SQL & PL/SQL » error when using return along with ref cursor (oracle 11g)
error when using return along with ref cursor [message #597353] Thu, 03 October 2013 11:36 Go to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
Hi Experts,

When I am executing the below procedure I am getting error.

ORA-24338: statement handle not executed

SET SERVEROUTPUT ON
variable r refcursor
DECLARE 
  P_EMPNO NUMBER;
  r_out sys_refcursor;   

BEGIN 
P_EMPNO := 12345; 
P_RET_VAL ( P_EMPNO,r_out);
  :r := r_out; 
END;
print r

CREATE OR REPLACE PROCEDURE P_RET_VAL
(P_EMPNO NUMBER,
p_dataset OUT SYS_REFCURSOR
)

IS
v_query VARCHAR2(100);
tcount NUMBER :=0;
BEGIN

SELECT COUNT(*) INTO tcount from emp WHERE empno=P_EMPNO;

IF tcount=0 THEN 
 RETURN;
END IF;
v_query :='SELECT * FROM emp';
OPEN p_dataset for v_query;
END;
/


How to resolve this error Please help me.

Thanks.
icon4.gif  Re: error when using return along with ref cursor [message #597355 is a reply to message #597353] Thu, 03 October 2013 11:49 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

There is no emp no 12345 and so on there is nothing in r.

Re: error when using return along with ref cursor [message #597356 is a reply to message #597355] Thu, 03 October 2013 12:15 Go to previous messageGo to next message
ajaykumarkona
Messages: 399
Registered: August 2010
Senior Member
Yes.

How to handle this scenario.

Please help me.

Thanks.
icon2.gif  Re: error when using return along with ref cursor [message #597357 is a reply to message #597356] Thu, 03 October 2013 12:44 Go to previous messageGo to next message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

How you have to handle it depends on how your specifications tell you what you have to return in this case.
Note that the whole procedure is meaningless if not surreal. Smile

Re: error when using return along with ref cursor [message #597358 is a reply to message #597356] Thu, 03 October 2013 12:50 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
Hello,

ajaykumarkona wrote on Thu, 03 October 2013 19:15
How to handle this scenario.

Instead of writing
IF tcount=0 THEN 
 RETURN;
END IF;

Check that your employee number is a valid one, and raise an exception (for example NO_DATA_FOUND) if it is not the case. Something like
DECLARE
    v_empid hr.employees.employee_id%TYPE;
BEGIN
    SELECT t1.employee_id INTO v_empid
    FROM   hr.employees t1
    WHERE  t1.employee_id = p_empno;
. . .
EXCEPTION
   WHEN NO_DATA_FOUND THEN
. . .


However, at the end of your code, you wrote
. . .
v_query :='SELECT * FROM emp';
OPEN p_dataset for v_query;

So no matter what the employee (valid) number is, you query the whole table. So what's the point of passing an employee number as the parameter of the procedure?

Regards,
Dariyoosh
icon10.gif  Re: error when using return along with ref cursor [message #597362 is a reply to message #597358] Thu, 03 October 2013 14:01 Go to previous message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
As I said "Note that the whole procedure is meaningless if not surreal.".
But, as we don't know the purpose of the procedure, maybe it is what OP wants: return the whole table if the given employee exists.
Note that you didn't answer the question "How to handle this scenario." Wink

[Updated on: Thu, 03 October 2013 14:20]

Report message to a moderator

Previous Topic: Change Max Partitionname
Next Topic: ORA-00904: : invalid identifier in oracle 11G
Goto Forum:
  


Current Time: Fri Apr 26 16:22:04 CDT 2024