Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

oracle

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

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;
like image 844
DJ180 Avatar asked Apr 20 '12 19:04

DJ180


Video Answer


2 Answers

Oracle PL/SQL functions must have 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't have a return).

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

BEGIN
    FOR attribute_record IN c_attributes
    LOOP
        ...
    END LOOP;
END;
like image 69
FrustratedWithFormsDesigner Avatar answered Oct 16 '22 00:10

FrustratedWithFormsDesigner


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

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

like image 31
DCookie Avatar answered Oct 15 '22 23:10

DCookie