oracle根据时间查询

[color=blue]
[size=large]
oracle根据时间查询主要有两个函数(
1、to_char(将时间类型转换成char类型);
2、to_date(将String类型转换成date类型);
例如,
1)表名:test_table,字段名:addtime,查询2012年3月12日的记录
select * from test_table t where to_char(t.addtime,'yyyy-MM-dd')='2012-03-12';
注:这个时候使用select * from test_table t where t.addtime=to_date('2012-03-12','yyyy-MM-dd')是不行的,because:数据库存储date类型的字段,会保存时分秒的;

2)表名:test_table,字段名:addtime,查询2012年3月12日0时0分0秒的记录:
select * from test_table t where to_char(t.addtime,'yyyy-MM-dd hh24:mi:ss')='2012-03-12 00:00:00';
或者:select * from test_table t where t.addtime=to_date('2012-03-12 00:00:00','yyyy-MM-dd hh24:mi:ss');

3)表名:test_table,字段名:addtime,查询2012年3月12日到2012年3月15日的记录:
select * from test_table t where to_char(t.addtime,'yyyy-MM-dd') between '2012-03-12' and '2012-03-15';
[/size]
[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值