oracle基础日期查询

开发中遇到了oracle的时间查询记录下来以便以后查阅
hibernate查询指定日期的数据:
String hql = "select bean from ZJczbJiPoTongJi bean where 1=1 ";
if(bean!=null && bean.getRiqi() !=null){
hql += "and to_char(bean.riqi,'yyyy-mm-dd') = "+"'"+dateFormat.format(bean.getRiqi())+"')";
}

查询当天,当周,当月的sql代码(没经过测试)

--查询当天的数据
select * from a where generateTime=sysdate
--查询一个星期的数据
select * from a where (sysdate-generaeTime)=7
--查询一个月的数据
select * from a where months_between(sysdate,generateTime)=1
--查询一年的数据
1.select * from table t
2.where t.create_time >=trunc(sysdate,'YYYY')
3.and t.create_time<=add_months(trunc(sysdate,'YYYY'),12)-1


日期查询to_date():
to_date('"+xxx+"', 'YYYY-MM-DD HH24:MI:ss') --得到的是一个时间格式

to_char:
to_char(t.locodate,'yyyy-mm')='2009-12' --得到的是字符串格式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值