因此,我有一个Sybase存储的proc,它使用1个参数,该参数是逗号分隔的字符串列表,并在IN()子句中使用in运行查询:

CREATE PROCEDURE getSomething @keyList varchar(4096)
AS
SELECT * FROM mytbl WHERE name IN (@keyList)


如何在列表中调用具有大于1的值的存储过程?
到目前为止,我已经尝试过

exec getSomething 'John'         -- works but only 1 value
exec getSomething 'John','Tom'   -- doesn't work - expects two variables
exec getSomething "'John','Tom'" -- doesn't work - doesn't find anything
exec getSomething '"John","Tom"' -- doesn't work - doesn't find anything
exec getSomething '\'John\',\'Tom\'' -- doesn't work - syntax error


编辑:我实际上发现了这个page,它对将数组粘贴到sproc的各种方式有很好的参考

最佳答案

如果使用的是Sybase 12.5或更早版本,则不能使用函数。一种解决方法是用值填充临时表并从中读取它们。

关于sql - 如何将逗号分隔的列表传递给存储过程?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6369/

10-10 16:23