Chinaunix首页 | 论坛 | 博客
  • 博客访问: 308301
  • 博文数量: 128
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1611
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-19 11:49
文章分类

全部博文(128)

文章存档

2018年(2)

2016年(2)

2014年(10)

2013年(114)

我的朋友

分类: Web开发

2013-10-31 10:52:40

正常写法:
 代码如下:

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;
阅读(959) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~