ORA-01843 „kein gültiger Monat“ und ORA-01861 „wörtliche Format-String stimmt nicht überein“
-
10-10-2019 - |
Frage
SQL> select to_timestamp('2010-12-14:09:56:53') - to_timestamp('2010-12-14:09:56:46') from dua
l;
select to_timestamp('2010-12-14:09:56:53') - to_timestamp('2010-12-14:09:56:46') from dual
*
ERROR at line 1:
ORA-01843: not a valid month
SQL> select to_date('2010-12-14:09:56:53') - to_date('2010-12-14:09:56:46') from dual;
select to_date('2010-12-14:09:56:53') - to_date('2010-12-14:09:56:46') from dual
*
ERROR at line 1:
ORA-01861: literal does not match format string
Was ist der richtige Weg, um ein
zu tun2010-12-14:09:56:53
minus
2010-12-14:09:56:46
in Oracle SQL?
Lösung
Sie haben Format angeben, dass die Zeitstempel-String ist in auf TO_TIMESTAMP
Funktionen:
select
to_date('2010-12-14:09:56:53', 'YYYY-MM-DD:HH24:MI:SS') -
to_date('2010-12-14:09:56:46', 'YYYY-MM-DD:HH24:MI:SS')
from dual;
Ergebnis in Tagen sein wird, die Sie mehrfach durch 86.400 Sekunden zu erhalten:
TO_DATE('2010-12-14:09:56:53','YYYY-MM-DD:HH24:MI:SS')-TO_DATE('2010-12-14:09:56
--------------------------------------------------------------------------------
.000081019
Mit TO_TIMESTAMP
:
select
to_timestamp('2010-12-14:09:56:53', 'YYYY-MM-DD:HH24:MI:SS') -
to_timestamp('2010-12-14:09:56:46', 'YYYY-MM-DD:HH24:MI:SS')
from dual;
Ergebnis in TIMESTAMP
Format sein:
TO_TIMESTAMP('2010-12-14:09:56:53','YYYY-MM-DD:HH24:MI:SS')-TO_TIMESTAMP('2
---------------------------------------------------------------------------
+000000000 00:00:07.000000000
Andere Tipps
Verwenden to_timestamp
select TO_TIMESTAMP('2010-12-14:09:56:53', 'YYYY-MM-DD:HH24:MI:SS.FF')
- TO_TIMESTAMP('2010-12-14:09:56:46', 'YYYY-MM-DD:HH24:MI:SS.FF')
from dual
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow