Když přidáte nebo odečtete časová razítka, výsledkem je interval
, nikoli další časové razítko. Můžete použít extract
funkce
vytáhnout z toho komponenty. Pokud vaše hodnota bude vždy nižší než sekunda, můžete jen extrahovat sekundy a vynásobit je tisíci, abyste získali milisekundy:
with t as (
select 1 as msg_guid,
interval '0 0:0:0.343009' day to second as diff
from dual
)
select trunc(extract (second from diff) * 1000)
from t;
TRUNC(EXTRACT(SECONDFROMDIFF)*1000)
-----------------------------------
343
Zde by váš skutečný dotaz nahradil fiktivní CTE, který jsem použil s intervalovým literálem.
Pokud by interval mohl být delší než jedna sekunda, pak byste pravděpodobně chtěli získat celou hodnotu v milisekundách, takže byste museli extrahovat všechny prvky a sečíst je dohromady, vynásobit každý podle toho, co představují - takže celý den by být 86400000 milisekund atd.; prosté prvky by vyšly takto:
column diff format a25
with t as (
select 1 as msg_guid,
systimestamp - trunc(systimestamp) as diff
from dual
)
select diff,
extract (day from diff) as dd,
extract (hour from diff) as hh,
extract (minute from diff) as mi,
extract (second from diff) as ss
from t;
DIFF DD HH MI SS
---------------------- ---------- ---------- ---------- ----------
0 9:13:26.150627 0 9 13 26.150627
A zkombinovali byste je takto:
with t as (
select 1 as msg_guid,
systimestamp - trunc(systimestamp) as diff
from dual
)
select diff,
trunc(1000 * (
extract (day from diff) * (60*60*24)
+ extract (hour from diff) * (60*60)
+ extract (minute from diff) * 60
+ extract (second from diff)
)) as milliseconds
from t;
DIFF MILLISECONDS
---------------------- ------------
0 9:13:27.650365 33207650
Ale na základě vaší předchozí otázky to možná chcete jako řetězec, jako samostatné komponenty:
with t as (
select 1 as msg_guid,
systimestamp - trunc(systimestamp) as diff
from dual
)
select diff,
extract (day from diff) || ' DAYS '
|| extract (hour from diff) || ' HOURS '
|| extract (minute from diff) || ' MINUTES '
|| trunc(extract (second from diff)) || ' SECONDS '
|| (trunc(extract (second from diff) * 1000)
- (trunc(extract (second from diff)) * 1000)) || ' MILLISECONDS'
as text
from t;
DIFF TEXT
---------------------- -------------------------------------------------------
0 9:43:38.896007 0 DAYS 9 HOURS 43 MINUTES 38 SECONDS 896 MILLISECONDS
SQL Fiddle na základě vašich ukázkových dat, tak nějak as výpočtem času obráceným, takže hodnota je kladná.