skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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 BEGINEND.

    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 ;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search