select * from t_goods_decl t where t.decl_date like '%'||(to_char(sysdate,'yyyy')||'-6')||'%'
我这样写却一条记录都查找不出来,但是日期像'2011-6'的记录还是不少的,是什么问题呢?
我这样写却一条记录都查找不出来,但是日期像'2011-6'的记录还是不少的,是什么问题呢?
解决方案 »
- 如何搬迁部分功能包和这些包相关对象到另一个库
- 如何在指定表空间中建表
- 求助:ORACLE数据导入的问题
- 征用一个批处理文件用于导出DMP文件
- 这么短的一个sql语句,我则么这么多不会的地方呢??
- 如何给时间字段增加15分钟?
- ORA-00942:table or view does not exist,很奇怪的一个问题,大家过来帮帮忙吧
- 关于触发器的问题!
- 如何察看一个用户都拥有哪些表或视图呢?
- 菜鸟求大神帮忙 PLSQL关于游标取数据的问题
- 如何使ORACLE的TABLE显示不是ID,而是DESCRIPTION 就像MS-Access的LOOK-UP table 功能一样?
- ORACLE 10G基本界面,谢谢
-- 如果是日期类型的话,最好这样写:select * from t_goods_decl t
where t.decl_date>=to_date('2011-06-01','yyyy-mm-dd')
and t.decl_date<to_date('2011-07-01','yyyy-mm-dd')
select * from t_goods_decl t where t.decl_date>=date'2011-06-01 and t.decl_date<date'2011-07-01';
如果列decl_date上有索引,才会利用上索引
但是,我先把它转成字符类型也不行啊select * from t_goods_decl t where to_char(t.decl_date,'yyyy-mm-dd')
like '%'||(to_char(sysdate,'yyyy')||'-6')||'%'
还是查找不出来.
但是,我先把它转成字符类型也不行啊select * from t_goods_decl t where to_char(t.decl_date,'yyyy-mm-dd')
like '%'||(to_char(sysdate,'yyyy')||'-06')||'%'-6 修改为 -06
select * from t_goods_decl t where to_char(t.decl_date,'yyyy-mm-dd')
like '%'||(to_char(sysdate,'yyyy')||'-06')||'%'
-- 其实这是低效的写法,具体示例请看:
http://topic.csdn.net/u/20110323/13/43a9766c-9a40-470d-8adb-9c2594282203.html
不要使用模糊匹配:
select * from t_goods_decl t
where t.decl_date >= to_date('2011-06-01','yyyy-mm-dd')
and t.decl_date < to_date('2011-07-01','yyyy-mm-dd');
如果想上面你的那么写:
where to_char(t.decl_date,'yyyy-mm-dd')
like '%'||(to_char(sysdate,'yyyy')||'-6')||'%'
decl_date列上有索引,查询时是不会走索引的
还有索引范围扫描是什么概念呢