I have written the following stored procedure:
DELIMITER $$
CREATE PROCEDURE `getroom`(OUT `free_room` INT)
BEGIN
SELECT room INTO free_room FROM admins WHERE free = 1 LIMIT 1 FOR UPDATE;
UPDATE admins SET free = 0 WHERE room = free_room;
END$$
DELIMITER ;
I am trying to query the table for free rooms, lock the row so other users cannot query it at the same time, and set it as not free at the end.
My questions are:
1) How can I call a stored procedure and get the free_room value automatically (as if i ran a SELECT statement) without doing an additional SELECT statement?
2) Since I am not passing any arguments (don't have "IN" values), why can't I run CALL getroom() succssfully? I get the following error:
Incorrect number of arguments for PROCEDURE getroom; expected 1, got 0
Hope my questions are clear enough!
CALL getroom(@somevar). Afterwards, the result will be available in@somevar.CALL getroom(@somevar)and get a return value without having to doCALL getroom(@somevar); SELECT @somevar;?