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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM