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')

  • 相关阅读:
    学习笔记——SQL SERVER2014内存数据库
    学习笔记——WCF
    线程
    文件内容操作类-RandomAccessFile
    文件操作类-file-创建文件夹
    同步方法解决同步问题
    同步代码块
    停止线程
    使用泛型来优化坐标类
    数据操作流-DataOutputStream
  • 原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884863.html
Copyright © 2011-2022 走看看