新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > 数据库 > 数据库综合 > 正文:“Select“语句究竟是如何来使用索引的?

“Select“语句究竟是如何来使用索引的?

新客网 XKER.COM 2008-02-02 来源:赛迪网 楠惜梦 收藏本文

用Select语句使用索引:

select * from t1 ;

--不能用索引,全表扫描

select * from t1 where age > 20;

--能用age上的索引

select * from t1 where name like '李%';

--能用上name上的索引

select * from t1 where xh <45;

--能用上xh上的索引;

select * from t1 where age > 20;

--能用索引

select * from t1 where age 10>30;

--不能用age上的索引

规则1:索引的字段不能参与运算

select * from t1 where substr(name,1,1)='李';

--不能用索引

规则2:索引的字段上不能使用函数

select * from t1 where name like '李%';

--能用索引

查询emp表中hiredate在1982年10月到1999年9月的员工??

select * from emp where to_char(hiredate,'yyyymm') 
>= '198210' and to_char(hiredate,'yyyymm') <='199909';
create index ind_hiredate on emp(hiredate);

--用不上hiredate上的索引

select * from emp where hiredate <= to_date('19990901','yyyymmdd') and 
hiredate >= to_date('19821001','yyyymmdd');

--能用上hiredate上的索引

收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐