位置:首页 > 网络编程 > 数据库
点击展开栏目简介
数据库技术,mysql,oracle

oracle:like模糊查询的优化

分享到: 微信 新浪微博 更多

第一种:like 'a%'这种,直接可走索引

第二种:like '%a'这种,需要用reverse反转函数改写SQL,再建立函数索引,如下:
  改写前:
   select * from test where owner like '%SCOTT'
   改写后:
   select * from test where reverse(owner) like reverse('%SCOTT');
第三种:like '%a%'这种的优化,使用Oracle内部函数:INSTR();

select   id, name from users where instr(id, '101') > 0;  

等价于
select   id, name from users where id like '%101%'

上篇:oracle:case when实现单条语句获取不同where条件下的count功能

下篇:mysql:like模糊查询的优化

发表评论 ​共有​条评论
  • 匿名发表