我想从结果中排除可变数量的用户/ ID。有没有办法将可变数量的用户名/ id传递给IN运算符?简化代码如下: -
CREATE DEFINER=`root`@`localhost` PROCEDURE `myroutine`(@userids)
--possible process here--
BEGIN
SELECT * FROM mytable WHERE `myid` NOT IN (@useridsprocessed)
END
答案 0 :(得分:0)
为了关闭,这是我可以开始工作的最佳答案,但它让我感到很乱。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `mytable`(IN excluded VARCHAR(255))
BEGIN
SET @sql = CONCAT('SELECT * FROM entries WHERE `id` NOT IN (', excluded,')');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
如下调用: -
SET @excluded = '\'19\',\'26\',\'27\'';
call liquidfinger.mytable(@excluded);