How to return a empty cursor from a stored procedure?

KeenUser picture KeenUser · Oct 9, 2012 · Viewed 14.6k times · Source

I have OUT parameter of a stored procedure as a REF CURSOR. Based on a particular condition, I would want to either return a result set (already implemented). But how do I return an empty cursor when the condition fails? Without raising an exception? Just pasting pseudo code:

IF condition = true THEN
   OPEN OUT_CUR FOR 
   Select Some query

ELSE

   Return empty OUT_CUR

END IF

Answer

Satya picture Satya · Oct 9, 2012

you can try this

IF condition = true THEN
   OPEN OUT_CUR FOR 
   Select Some query;
ELSE
   OPEN OUT_CUR FOR 
       Select * from mtable where 1=2;
END IF
return OUT_CUR;