Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql存储过程传递字符串列表_Mysql_Sql_Database_Stored Procedures - Fatal编程技术网

Mysql存储过程传递字符串列表

Mysql存储过程传递字符串列表,mysql,sql,database,stored-procedures,Mysql,Sql,Database,Stored Procedures,我在下面有一个存储过程,如果我的PostId是整数,它就可以工作 我将postdlist作为逗号分隔的字符串“1,2,3,4”发送。。。 但如果我将posted更改为GUID(char(36)),它对我不起作用。 它给我一个语法错误,说 “错误代码:1064。您的SQL语法有错误;请检查 与右边的MySQL服务器版本相对应的手册 第1行使用“2d9d3ebc-6c9f-467a-8181-8a38891756b”附近的语法 这就是我所说的 调用GetComments( ‘fff78ee0-396

我在下面有一个存储过程,如果我的PostId是整数,它就可以工作 我将postdlist作为逗号分隔的字符串“1,2,3,4”发送。。。 但如果我将posted更改为GUID(char(36)),它对我不起作用。 它给我一个语法错误,说

“错误代码:1064。您的SQL语法有错误;请检查 与右边的MySQL服务器版本相对应的手册 第1行使用“2d9d3ebc-6c9f-467a-8181-8a38891756b”附近的语法

这就是我所说的 调用GetComments( ‘fff78ee0-396b-4300-952b-eee72d65261a,fff517dc-a7b7-441e-85bb-b5134828c0c9’


有什么办法解决这个问题吗?

您的ID不是整数。您需要用单引号将它们传入,或者执行类似操作:

set @sql = CONCAT('select * from PostComment where PostId in (''',
                  replace(postIdList, ',', ''','''),
                  ''') ');
也就是说,用单引号替换每个逗号,逗号,单引号。然后在列表的开头和结尾加引号

set @sql = CONCAT('select * from PostComment where PostId in (''',
                  replace(postIdList, ',', ''','''),
                  ''') ');