如何在 MySQL 中循环使用数组?
我想用数组传递的值创建一个存储过程或一个普通查询.
I'd like to create a stored procedure or a normal query with values passed with an array.
示例:
CREATE PROCEDURE proc()
BEGIN
DECLARE cont INTEGER;
DECLARE var ARRAY;
SET cont = 0;
SET var = ("hi", "hello", "good", ...)
WHILE cont < 12 DO
SELECT * FROM tablex
WHERE name = var[cont];
SET cont = cont + 1;
END WHILE;
END;
显然这是行不通的,但我想知道如何实现这一点.
Obviously this is will not work, but I'd like to know how to achieve this.
推荐答案
尽量不用存储例程 -
SET @arr = 'hi,hello,good'; -- your array
SELECT COUNT(*) FROM tablex
WHERE FIND_IN_SET (name, @arr); -- calculate count
相关文章