mysql存储过程一个参数有多个逗号分割
2个回答
展开全部
这个应该可以使用字符串拼接,你是不是这样写存储过程:
create procedure p_proc(var_in int)
begin
delete from [tableName] where [colName] in (var_in);
end
然后又这样调用:
call p_proc(1, 2, 3);
这样肯定不行,那么你可以这样:
create procedure p_proc(var_in varchar(5000))
begin
set @sql = concat("delete from [tableName] where [colName] in (", var_in, ")");
prepare stmt_exe_sql from @sql;
execute stmt_exe_sql;
deallocate prepare stmt_exe_sql;
end
这样就相当于把(1, 2, 3)拼接成语句"delete from [tableName] where [colName] in (1, 2, 3)", 然后执行,就可以删除了。
create procedure p_proc(var_in int)
begin
delete from [tableName] where [colName] in (var_in);
end
然后又这样调用:
call p_proc(1, 2, 3);
这样肯定不行,那么你可以这样:
create procedure p_proc(var_in varchar(5000))
begin
set @sql = concat("delete from [tableName] where [colName] in (", var_in, ")");
prepare stmt_exe_sql from @sql;
execute stmt_exe_sql;
deallocate prepare stmt_exe_sql;
end
这样就相当于把(1, 2, 3)拼接成语句"delete from [tableName] where [colName] in (1, 2, 3)", 然后执行,就可以删除了。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询