How can I get and assign the return value from MySQL stored procedure

10,082
CREATE DEFINER=`root`@`localhost` PROCEDURE `getUserIdByLogin`(
   userId VARCHAR(255),
   OUT idout int
)
BEGIN
    SELECT id INTO idout FROM `userdata` WHERE login = userId;
END

then

SET @id = 0;
CALL getUserIdByLogin("someLogin",  @id);
SELECT @id;
Share:
10,082
Admin
Author by

Admin

Updated on June 05, 2022

Comments

  • Admin
    Admin almost 2 years

    I have the next stored procedure:

    DELIMITER $$
    
    CREATE DEFINER=`root`@`localhost` PROCEDURE `getUserIdByLogin`(userId VARCHAR(255))
    BEGIN
        SELECT id FROM `userdata` WHERE login = userId;
    END
    

    I want to declare a new variable @tmp for e.g. and do smth to this:

    SET @tmpValue = CALL getUserIdByLogin("someLogin");
    

    But it doesn't work.

    If just to call:

    CALL getUserIdByLogin("someLogin");
    

    Then I would see results, but I need to declare the results in the variable ( of array type ).

    How can I do it?

    Thanks!