简体   繁体   中英

MySQL stored procedure always getting empty values

I am very new to stored procedure. I am trying to write a very basic stored procedure. And here it is:

DELIMITER //

    CREATE PROCEDURE `getname` (IN a_id INT, OUT a_name VARCHAR(50))

    BEGIN
         SELECT name INTO a_name FROM tblname WHERE id = a_id;
    END //

DELIMITER ;

I have a very very simple database with a single table, a single rows in it with id 1 and a string value as name. Each time I call the procedure like:

CALL getname(1, @a_name);
SELECT @a_name;

it always returns NULL values :(

I am sitting for last 4 hours with this simple problem but still no luck. Hope to get a solution from you guys.

BTW, I am using XAMPP 1.7.1 for windows 32 bit with MySQL version is 5.1.33.

Try in this session -

CALL getname(1, @a_name);
SELECT @a_name;

SELECT * FROM tblname WHERE id = 1; -- Is there any result?

If result is not empty, then try to run this SELECT statement from the procedure -

...
BEGIN
  SELECT * FROM tblname WHERE id = 1;
END//
...

And call it again.

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