我有一个autos
有列的表name
,我想检查表中的前 5 行,如果name
值是"toyota"
,在表中mytable
写“是”,否则写“否”。我编写存储过程,但mysqli_error()
在行中返回错误,我有EXECUTE ...
.
如果WHEN
我不是写PREPARED STATEMENT
,而是直接写查询,则该过程有效。请查看我的代码并告诉我,哪里错了?
CREATE PROCEDURE proc_auto()
BEGIN
DECLARE start INT;
SET start = 0;
PREPARE stmt FROM ' SELECT name FROM autos ORDER BY id LIMIT ?,1 ';
WHILE start < 5 DO
CASE
WHEN (EXECUTE stmt USING @start ) = 'toyota'
THEN INSERT INTO mytable (log) VALUES('yes');
ELSE
INSERT INTO mytable (log) VALUES('no');
END CASE;
SET start = start + 1;
END WHILE;
END;