Lince Assassino
Lince Assassino

Reputation: 111

"No Return Found" error in simple mysql function

I'm using xampp with phpMyAdmin to manage a MySql database. When creating a function I got a "No Return Found" error, so I stripped down the function to narrow the origin of the error I got to the simplest case where it still doesn't work.

Code

And the error message is this:

Error message

Apparently if the RETURN statement isn't the only thing on the code I get an error.

Upvotes: 0

Views: 508

Answers (2)

Martin
Martin

Reputation: 16433

Assuming the actual code being executed against MySQL is:

CREATE FUNCTION `Contagem`() RETURNS INT(11)
SET @c = 0;
RETURN @c;

This will fail, because you have not wrapped the function in BEGIN...END.

Try instead to write this as your function declaration:

BEGIN
    SET @c = 0;
    RETURN @c;
END;

Alternatively, declare the function yourself directly in MySQL:

DELIMITER $$

CREATE FUNCTION `Contagem`() RETURNS INT(11)
BEGIN
    SET @c = 0;
    RETURN @c;
END $$

DELIMITER ;

Upvotes: 3

Lince Assassino
Lince Assassino

Reputation: 111

When reviewing this post I was reading more carefully the error message I realized the MySql code to define the function didn't have BEGIN and END in it.

I assumed when typing function code with several lines that phpMyAdmin would know how to handle it, since the code text box has support to multiple lines of code.

So, putting BEGIN at the beginning and END at the end of the code solved my problem.

Upvotes: 1

Related Questions