11

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;
1
  • 9
    A function...without a return...is a procedure. A donut...without a hole...is a danish. Commented Apr 21, 2012 at 3:11

2 Answers 2

19

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;
Sign up to request clarification or add additional context in comments.

4 Comments

Procedures CAN have a return statement. You can't return a value, and it's not required, but you can use RETURN in your procedure.
@DCookie: So what does RETURN; do in a procedure? Does it just end execution of the procedure of it right there?
It leaves the procedure and returns to the caller.
Thanks, I wasn't aware that a function must always return a value. This helps
4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.