MySQL 存储过程传参数实现where id in(1,2,3,...)示例
2013-10-30 00:00
1131 查看
正常写法:
当在写存储过程in里面的列表用个传入参数代入的时候,就需要用到如下方式:
主要用到find_in_set函数
当然还可以比较笨实的方法,就是组装字符串,然后执行:
select * from table_name t where t.field1 in (1,2,3,4,...);
当在写存储过程in里面的列表用个传入参数代入的时候,就需要用到如下方式:
主要用到find_in_set函数
select * from table_name t where find_in_set(t.field1,'1,2,3,4');
当然还可以比较笨实的方法,就是组装字符串,然后执行:
DROP PROCEDURE IF EXISTS photography.Proc_Test; CREATE PROCEDURE photography.`Proc_Test`(param1 varchar(1000)) BEGIN set @id = param1; set @sel = 'select * from access_record t where t.ID in ('; set @sel_2 = ')'; set @sentence = concat(@sel,@id,@sel_2); -- 连接字符串生成要执行的SQL语句 prepare stmt from @sentence; -- 预编释一下。 “stmt”预编释变量的名称, execute stmt; -- 执行SQL语句 deallocate prepare stmt; -- 释放资源 END;
相关文章推荐
- MySQL 存储过程传参数实现where id in(1,2,3,...)示例
- MySQL 存储过程传参数实现where id in('40288c81494f088601494f92938d0002,40288c81494f088601494f92938d0012,')示例
- MySQL 存储过程传参数实现where id in(1,2,3,...)示例
- MySQL 存储过程传参数问题:实现 where id in(1,2,3,...)
- MySQL 存储过程传参数问题:实现 where id in(1,2,3,...)
- MySQL 存储过程传参数问题:实现 where id in(1,2,3,...)
- MySQL 存储过程传参数问题:实现 where id in(1,2,3,...)
- MySQL 存储过程或者函数中传参数实现where id in(1,2,3,...)IN条件拼接
- SQL实现递归及存储过程中In()参数传递解决方案详解
- MySQL 存储过程参数用法 in, out, inout(转)
- 如何在MySQL的存储过程中实现把过程参数用在游标定义的SELECT命令里面作为表名引用
- MySQL存储过程传参之in,out,inout参数用法
- MySQL 存储过程参数用法 in, out, inout
- MySQL 存储过程传参之in, out, inout 参数用法
- MySQL 存储过程参数用法 in, out, inout
- 存储过程中动态条件的添加 where条件 in条件中字符串参数
- MySQL 存储过程参数用法 in, out, inout
- 详解MySQL存储过程参数有三种类型(in、out、inout)
- mysql存储过程中in、out、inout参数使用实际案例
- SQL实现递归及存储过程中In()参数传递解决方案[转]