MySQL 存储过程或者函数中传参数实现where id in(1,2,3,...)IN条件拼接
2017-01-22 17:48
676 查看
正常写法: 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(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('40288c81494f088601494f92938d0002,40288c81494f088601494f92938d0012,')示例
- sql 自定义函数 ,where后拼接条件跳转语句,实现可变参数查询
- MySQL 存储过程传参数问题:实现 where id in(1,2,3,...)
- 创建存储过程,以部门编号为参数返回该部门的人数及平均工资(返回一个值可以通过函数来实现,但如果要返回多个值,需要使用out或in out模式参数实现)
- MYSQL存储过程实现in传入参数 where in('1','2')
- 关于sql条件语句where id in (@参数)执行报错问题(转换成数据类型 int 时失败)(
- sql 存储过程 where条件 in 字符串参数
- 存储过程中动态条件的添加 where条件 in条件中字符串参数
- MySql的sql语句中添加存储过程或者存储函数来实现Oracle中的start with ……connect by prior……递归(树形结构数据)查询
- 实现函数 functionFunction,调用之后满足如下条件: 1、返回值为一个函数 f 2、调用返回的函数 f,返回值为按照调用顺序的参数拼接,拼接字符为英文逗号加一个空格,即 ', ' 3、所
- Mysql where in中的参数传入字符串(字符串拼接)
- mysql group by内排序的实现以及having和where 条件语句查询的区别
- mysql/sqlserver where in 传参数的问题
- 在 SQL Server 2K 中实现 大小写敏感的查询条件(WHERE ...),类似 Access(VB) 的 StrComp 函数