Oracle:PL/SQL 函数可能不返回任何内容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10252619/
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-01 15:25:44  来源:igfitidea点击:

Oracle: Possible to return nothing from PL/SQL function?

sqloracle

提问by JJ180

As the title says, is it possible to return nothing from a PL/SQL function?

正如标题所说,是否可以从 PL/SQL 函数中不返回任何内容?

My function is as follows, and I am getting errors when I leave out the return:

我的功能如下,当我省略返回时出现错误:

create or replace
FUNCTION DeleteAttributes
(code IN varchar2)
CURSOR c_attributes = SELECT ...

BEGIN
    FOR attribute_record IN c_attributes
    LOOP
        ...
    END LOOP;
END;

回答by FrustratedWithFormsDesigner

Oracle PL/SQL functions musthave a return. If you declare your subprogram as a procedure, then it won't give you errors when it is lacking a return (procedures can'thave a return).

Oracle PL/SQL 函数必须有返回值。如果你将你的子程序声明为一个过程,那么当它没有返回时它不会给你错误(过程不能有返回)。

create or replace
PROCEDURE DeleteAttributes
(code IN varchar2)
CURSOR c_attributes = SELECT ...

BEGIN
    FOR attribute_record IN c_attributes
    LOOP
        ...
    END LOOP;
END;

回答by DCookie

By definition, a function returns a value, so you must have a RETURN statement. Have a look at the syntax definition for a functionin the Oracle documentation. RETURN is not an option.

根据定义,函数返回一个值,因此您必须有 RETURN 语句。查看Oracle 文档中函数语法定义。RETURN 不是一个选项。

I'm not even sure why you would want to do this.

我什至不确定你为什么要这样做。