0

I am trying to have a conditional change in a parameter for update statement. I am getting the following error when I try the following function

/home/y/bin/mysql -u root < testpri.sql > out
ERROR 1415 (0A000) at line 4: Not allowed to return a result set from a function

Contents of testpri.sql are as follows:

use `zestdb`;
DROP FUNCTION IF EXISTS UPDATEPASSWD;
DELIMITER //
CREATE FUNCTION UPDATEPASSWD(n INT) RETURNS varchar(255) DETERMINISTIC 
BEGIN
    DECLARE mypasswd varchar(255);
    IF (n = 1) THEN
       SET mypasswd = '12ccc1e5c3c9203af7752f937fca4ea6263f07a5';
       SELECT 'n is 1' AS ' ';
    ELSE
       SET mypasswd = '1a7bc371cc108075cf8115918547c3019bf97e5d';
       SELECT 'n is 0' AS ' ';
    END IF;>
    SELECT CONCAT('mypasswd is ', mypasswd) AS ' ';
    RETURN mypasswd;
END //
DELIMITER ;
CALL UPDATEPASSWD(0);

What am I missing?

2 Answers 2

2

I think it's actually your debugging SELECT calls.

From the docs:

Statements that return a result set can be used within a stored procedure but not within a stored function. This prohibition includes SELECT statements that do not have an INTO var_list clause...

Sign up to request clarification or add additional context in comments.

Comments

0

I arrived in search of answers to the same question, and found another way to work around the issue, so that I can use the SELECT statement that is the heart and soul of the MySQL function that elicited the warning.

Consider the following snippet.

SET intNMatches = ( SELECT COUNT(*) ...

SET coerces the SELECT statement to return its one and only column, a row count, into intNMatches, a local variable cast to BIGINT. Since it contains trade secrets, I can't show the rest of the query. Suffice it to say that the query installs without causing the MySQL engine to issue a warning.

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.