我要查询表数据, 根据:表某列中值=传入参数值 但是我要多个传入值 如: 查某列是否存在 “111,222,333” 我使用的是 '传入值' like '%列值%'
如: select * from tablename tb where '111,222,333' like tb.colunmName ;
(tablename:表名,
tb.colunmName: 代指表中某列,
'111,222,333' : 外传入参数 );
还有没有更好的方法更快的查询????
如: select * from tablename tb where '111,222,333' like tb.colunmName ;
(tablename:表名,
tb.colunmName: 代指表中某列,
'111,222,333' : 外传入参数 );
还有没有更好的方法更快的查询????
select * from tablename tb
where tb.colunmName in(111,222,333)
select * from tablename tb where tb.colunmName in (111,222,333);
--匹配
select * from tb
where tb.col_name like '%111,222,333%';
--
--instr函数
select * from tb
where instr(tb.col_name,'111,222,333','222')>0;
with t as(
select 1 id,'12,125,378' chr from dual union all
select 2,'0,111,222,333,1012' from dual union all
select 3,'111' from dual union all
select 4,'222' from dual union all
select 5,'333' from dual)
--
select * from t
where chr like '%111,222,333%'; ID CHR
---------- ------------------
2 0,111,222,333,1012
--
select * from t
where chr like '%111%' or
chr like '%222%' or
chr like '%333%' or
chr like '%25%'; ID CHR
---------- ------------------
1 12,125,378
2 0,111,222,333,1012
3 111
4 222
5 333
--
select * from t
where instr(chr,'111,222,333')>0; ID CHR
---------- ------------------
2 0,111,222,333,1012
用instr 加个函数index试试
in的速度最快但是英文字母的就不好组合
instr函数通用性好点 但是instr方法使用好像有点问题
like可以但效率不怎么样 我查了资料是 INSTR(源字符串, 目标字符串, 起始位置, 匹配序号)
源字符串:即传入字符串
目标字符串:表的某列
起始位置:从什么地方开始(数字) (如:1 .... 负数为从右开始找)
匹配序号:第几个同的(数字)