Oracle以毫秒为单位计算时间差的实现代码。
我们知道,甲骨文可以以秒计算的,日,月,年,周,与to_date功能的时间差,但却没有计算,to_date功能只能精确到秒,毫秒,可用于to_timestamp功能,但不同的功能to_date直接还原号码类型,如果转换,使用to_number功能将是一个错误。
这里,我使用分隔符字符串分别计算毫秒部分。如果有更好的方法,请分享它。下面是毫秒时间差的模板(字段1到字段2)。
选择
(
(
(to_timestamp(字段1,'yyyy-mm-dd hh24:MI:SS。ff9 ')+ 0)
—
(to_timestamp(字段2,'yyyy-mm-dd hh24:MI:SS。ff9 ')+ 0)
***********60 24;60
+
to_number
(
0| |
(
to_number(substr(1场,包括(1,)))
—
to_number(substr(2场,包括(2,)))
)
)
* * 1000
从表名
这里是毫秒数的区别,如果你需要显示一个小数秒,请删除()*()* 1000部分,下面是一个测试代码,直接运行:
选择
(
(
(to_timestamp('2016-04-13 17:13:50.998 ','yyyy-mm-dd hh24:MI:SS。ff9 ')+ 0)
—
(to_timestamp('2016-04-13 17:13:47.235 ','yyyy-mm-dd hh24:MI:SS。ff9 ')+ 0)
***********60 24;60
+
to_number
(
0| |
(
to_number(substr('2016-04-13 17:13:50.998,仪器('2016-04-13 17:13:50.998)))
—
to_number(substr('2016-04-13 17:13:47.235,仪器('2016-04-13 17:13:50.235)))
)
)
* * 1000
从双
研究结果如下:3763
tag:单位计算时间差代码电脑软件
相关内容