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

    Oracle 查询今天、昨日、本周、本月和本季度的所有记录

    www.MyException.Cn  网友分享于:2013-07-17  浏览:351次
    Oracle 查询今日、昨日、本周、本月和本季度的所有记录
    1. 字段类型为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')

  • 相关阅读:
    2018-04-13Java编程夯实学习心得(3)
    2018-03-28JavaScript学习心得
    2018-03-27mysql学习心得
    JavaScript-作用域
    样式切换图
    购物车结算
    Visual Studio Code快捷键操作
    复选框
    win10锁屏界面无法设置隐藏
    轮播图
  • 原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884863.html
Copyright © 2011-2022 走看看