Når du trækker to variabler af typen TIMESTAMP
fra , får du en INTERVAL DAY TO SECOND
som omfatter et antal millisekunder og/eller mikrosekunder afhængigt af platformen. Hvis databasen kører på Windows, systimestamp
vil generelt have millisekunder. Hvis databasen kører på Unix, systimestamp
vil generelt have mikrosekunder.
1 select systimestamp - to_timestamp( '2012-07-23', 'yyyy-mm-dd' )
2* from dual
SQL> /
SYSTIMESTAMP-TO_TIMESTAMP('2012-07-23','YYYY-MM-DD')
---------------------------------------------------------------------------
+000000000 14:51:04.339000000
Du kan bruge EXTRACT
funktion til at udtrække de individuelle elementer i en INTERVAL DAY TO SECOND
SQL> ed
Wrote file afiedt.buf
1 select extract( day from diff ) days,
2 extract( hour from diff ) hours,
3 extract( minute from diff ) minutes,
4 extract( second from diff ) seconds
5 from (select systimestamp - to_timestamp( '2012-07-23', 'yyyy-mm-dd' ) diff
6* from dual)
SQL> /
DAYS HOURS MINUTES SECONDS
---------- ---------- ---------- ----------
0 14 55 37.936
Du kan derefter konvertere hver af disse komponenter til millisekunder og lægge dem sammen
SQL> ed
Wrote file afiedt.buf
1 select extract( day from diff )*24*60*60*1000 +
2 extract( hour from diff )*60*60*1000 +
3 extract( minute from diff )*60*1000 +
4 round(extract( second from diff )*1000) total_milliseconds
5 from (select systimestamp - to_timestamp( '2012-07-23', 'yyyy-mm-dd' ) diff
6* from dual)
SQL> /
TOTAL_MILLISECONDS
------------------
53831842
Normalt er det dog mere nyttigt at have enten INTERVAL DAY TO SECOND
repræsentation eller at have separate kolonner for timer, minutter, sekunder osv. i stedet for at beregne det samlede antal millisekunder mellem to TIMESTAMP
værdier.