我想查询指定日期的该月份以前的该年度所有数据。 用如下语句可以完成,但觉得太长,可有简便方法? SELECT distinct theDate FROM TABLE WHERE trunc(to_char(to_date('2005-9-01','yyyy-mm-dd'),'yyyy')-to_char(theDate,'yyyy'))=0 AND trunc(to_char(to_date('2005-9-01','yyyy-mm-dd'),'yyyymm')-to_char(theDate,'yyyymm'))<0 以上是查询2005年1月到8月的时间。 SELECT distinct theDate FROM TABLE WHERE theDate between to_date('2005-01-01','yyyy-mm-dd') and to_date('2005-9-01','yyyy-mm-dd') 假设theDate的形式:'2005-09-01'(指定日期) SELECT distinct theDate FROM TABLE WHERE substr(theDate,1,7) <=substr('2005-09-01',1,7) and substr(theDate,1,7)=substr('2005-09-01',1,4) 为什么要用这么长呢? 如果你的数据类型是date类型的. 直接 看你的date格式是什么: 改为aalter session set nls_date_format='yyyy/mm/dd' select * from tname where theDate<=to_date('20050901','yyyy/mm/dd') and theDate>=to_date('20040901','yyyy/mm/dd') 注明:上面的是从CSDN上CP过来,地址如下: http://topic.csdn.net/t/20050906/17/4253264.html

评论