热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

两个时间戳之间的ORACLEsql小时格式[重复]-ORACLEsqlhoursbetweentwotimestampsformat[duplicate]

Thisquestionalreadyhasananswerhere:这个问题在这里已有答案:Calculatingdifferencebetweentwo

This question already has an answer here:

这个问题在这里已有答案:

  • Calculating difference between two timestamps in Oracle in milliseconds 9 answers
  • 以毫秒为单位计算Oracle中两个时间戳之间的差异9个答案

I have table:

我有桌子:

CREATE TABLE B(
...
date1 TIMESTAMP(6),
date2 TIMESTAMP(6),
...);

and I want to get hours between two timestamps. So I run query:

我想在两个时间戳之间得到几个小时。所以我运行查询:

SELECT (date1 - date2)*24 from B;

Result looks like this: +000000024 00:00:00.000000 but I want something like 24:00. How I can format the query? Thanks

结果如下所示:+000000024 00:00:00.000000但我想要24:00这样的东西。我如何格式化查询?谢谢

2 个解决方案

#1


Just use a subquery to extract the hours from the expression

只需使用子查询从表达式中提取小时数

SELECT  extract( hour from x) hours FROM
(SELECT (date1 - date2)x FROM B)

#2


SELECT to_char((date1 - date2)*24,'HH24:MI') from B;

推荐阅读
author-avatar
vaaal52653
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有