Question

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!

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top