正文

oracle对时间的匹配2007-08-09 21:15:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/daweizhao/28355.html

分享到:

我想查询指定日期的该月份以前的该年度所有数据。     用如下语句可以完成,但觉得太长,可有简便方法?         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

阅读(2630) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册