6

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
4

2 回答 2

17

你可以试试这个

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;
于 2012-10-09T04:33:24.877 回答
0
IF condition = true THEN
   OPEN OUT_CUR FOR 
   Select Some query

ELSE

    OPEN OUT_CUR FOR select * from unnest(array[1,2]) arr where  false 

END IF
于 2020-05-28T15:32:50.573 回答