首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

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

2013-07-16 
Oracle 查询今日、昨日、本周、本月和本季度的所有记录字段类型为date今日?select * from 表名 where to_char

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

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

热点排行