我正在尝试计算时差,例如:
from 10:00 to 11:30
它必须显示1:30 - 这是差异 - 但它显示我00000000 1:30:000000
如何让这个选择语句显示这个答案?我尝试了很多东西,但它不起作用。
select TO_CHAR(TO_TIMESTAMP(ARRIVAL,'HH:MI:SS') - (TO_TIMESTAMP (START,'HH:MI:SS'))) as Du
from passenger;
答案 0 :(得分:0)
to_char
最外层应用程序的参数实际上属于INTERVAL DAY TO SECOND
类型,并且没有关联的格式模型。诀窍是通过添加00:00:00
的时间戳将该值转换回时间戳:
select TO_CHAR( TO_TIMESTAMP('00:00:00','HH24:MI:SS') + (TO_TIMESTAMP(ARRIVAL,'HH:MI:SS') - TO_TIMESTAMP (START,'HH:MI:SS')), 'HH24:MI') as Du from passenger;
-- for testing on dual
select TO_CHAR( TO_TIMESTAMP('00:00:00','HH24:MI:SS') + (TO_TIMESTAMP('11:30:00','HH:MI:SS') - TO_TIMESTAMP ('10:00:00','HH:MI:SS')), 'HH24:MI') as Du from dual;