oracle 如何从存储过程返回空游标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12792768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:09:51  来源:igfitidea点击:

How to return a empty cursor from a stored procedure?

oraclestored-procedurescursorref-cursor

提问by KeenUser

I have OUTparameter 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:

我有OUT一个存储过程的参数作为REF CURSOR. 根据特定条件,我想返回一个结果集(已实现)。但是当条件失败时我如何返回一个空游标?不抛出异常?只是粘贴伪代码:

IF condition = true THEN
   OPEN OUT_CUR FOR 
   Select Some query

ELSE

   Return empty OUT_CUR

END IF

回答by Satya

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;

回答by Vusal Hasanli

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