简体   繁体   中英

Error when using function: The used SELECT statements have a different number of columns

In my MySQL database I have defined a function called isUserVerified that return the status of a user.

I am trying to use the function in a SQL statement:

SELECT 
    id, isUserVerified(id) AS verification
FROM
    users

But I get the following error:

1222 - The used SELECT statements have a different number of columns

This is my function definition:

BEGIN
    DECLARE isVerified VARCHAR(10);

    SELECT 
        users.profile_verification, users.id
    INTO 
        isVerified
    FROM 
        users 
    WHERE 
        users.id = user_id;

    RETURN isVerified;
END

What am I missing?

You are selecting two columns but inserting into only one variable. Presumably, you intend:

SELECT users.profile_verification
INTO isVerified

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM