
select cast(to_date('2012-11-2 13:29:19','yyyy-mm-dd hh24:mi:ss') as timestamp) - cast(to_date('2012-11-2 13:27:14','yyyy-mm-dd hh24:mi:ss')as timestamp) from dual
有两种方法:
1)
select to_char(to_date(substr(to_char(sysdate,'hh24:mi:ss'),0,2)-1,'hh24:mi:ss'),'hh24:mi:ss')
from dual(此处是我自定义的表明);
2)
select to_char(to_date(substr(to_char(sysdate-1/24,'hh24:mi:ss'),0,2),'hh24:mi:ss'),'hh24:mi:ss')
from dual(此处是我自定义的表明);;
你可以建个视图,create view as select ,to_char(datatime,'yy-mm-dd hh24')as 时间段 from a,然后用这个时间段做统计查询。
分两种情况,一种是创建表时自动创建带有默认值的字段,一种是把没有默认值的字段设置为有默认值的字段。
第一种情况:
create table test(id int,
starttime date default sysdate not null );
插入测试数据:
insert into test (id) values (1);commit;
验证结果:
第二种情况,比如在test表中加一个endtime,时间也要求是系统默认时间。
添加字段且不设置默认值:
alter table test add endtime date;添加默认值语句:
alter table test modify endtime default sysdate;测试语句:
insert into test (id) values (2);commit;
验证结果:
以上就是关于Oracle怎么把两个时间差转换成小时,分钟,秒全部的内容,包括:Oracle怎么把两个时间差转换成小时,分钟,秒、Oracle sysdate得到当前时间的前一个小时,精确到小时、oracle 取时间段中的整点数据,比如说 一天内 每个小时整点的数据。谢谢。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)