zoukankan      html  css  js  c++  java
  • Oracle 查询今天、昨日、本周、本月和本季度的所有记录

    Oracle 查询今日、昨日、本周、本月和本季度的所有记录
    
    字段类型为date
    今日
    select * from 表名 where to_char(字段名,'dd')=to_char(sysdate,'dd')
    昨日
    select * from  表名 where to_char(字段名,'dd')= to_char(sysdate-1,'dd')
    本周 
     select * from 表名 where to_char(字段名,'iw')=to_char(sysdate,'iw') 
    本月 
     select * from 表名 where to_char(字段名,'mm')=to_char(sysdate,'mm') 
    本季度 
     select * from 表名 where to_char(字段名,'q')=to_char(sysdate,'q')
     
       2.  字段类型为varchar2,格式要与格式化的样式匹配
    今日 
    select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'dd')=to_char(sysdate,'dd')
    昨日
    select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'dd')=to_char(sysdate-1,'dd') 
    本周 
    select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'iw')=to_char(sysdate,'iw') 
    本月 
    select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'mm')=to_char(sysdate,'mm') 
    本季度 
    select * from 表名 where to_char(to_date(字段名,'yyyy-mm-dd hh24:mi:ss'),'q')=to_char(sysdate,'q')
    ​
  • 相关阅读:
    PL/SQL详细介绍
    Linux服务器性能评估(转)
    oracle命令(转)
    Makefile介绍(转)
    delphi 指针
    浏览器的工作原理(转)
    高性能分布式计算与存储系统设计概要(上)(转)
    HTTP协议详解(转)
    MySQL性能优化(转)
    redhat 6.2安装telnet服务
  • 原文地址:https://www.cnblogs.com/suruozhong/p/5974600.html
Copyright © 2011-2022 走看看