oracle模糊查询 包含1,而不包含11,的数据

aaa表数据如下:
序号 name rowid
1 1, AAEfLQAAJAALrdkAAA
2 11, AAEfLQAAJAALrdkAAB
3 12, AAEfLQAAJAALrdkAAC
4 13, AAEfLQAAJAALrdkAAD

[color=red]select * from aaa where name like '%,1,%' or name like '1,%' or name ='1' or name like '%,1' [/color]

亲测好用
[color=blue]出于数据库查询效率
应尽量避免在where 子句中使用or来连接条件,否则将导致引擎放弃使用索引而进行全表扫描

这种方式比较好
select name from aaa where name like '%,1,%'
union all
select name from aaa where name like '1,%'
union all
select name from aaa where name ='1'
union all
select name from aaa where name like '%,1'[/color]

你可能感兴趣的:(oracle数据库)