Oracle stores dates in tables as 7-bytes
Byte 1 - Jahrhundert + 100
Byte 2 - (Jahr MOD 100) + 100
Byte 3 - Monats
Byte 4 - Tag
Byte 5 - Stunde + 1
Byte 6 - Minute + 1
Byte 7 - Sekunden + 1
So 120,116,3,6,1,1,1
konvertiert zu:
Byte 1 - Jahrhundert = 120 - 100 = 20
Byte 2 - year = 116-100 = 16
Byte 3 - Monat = 3
Byte 4 - Tag = 6
Byte 5 - Stunde = 1 - 1 = 0
Byte 6 - Minute = 1 - 1 = 0
Byte 7 - Sekunden = 1 - 1 = 0
So 2016-03-06T00:00:00
Oracle-Setup:
CREATE TABLE file_upload (file_blob BLOB);
INSERT INTO file_upload VALUES (
utl_raw.cast_to_raw(
CHR(120) || CHR(116) || CHR(3) || CHR(6) || CHR(1) || CHR(1) || CHR(1)
)
);
Abfrage:
SELECT DUMP(DBMS_LOB.SUBSTR(file_blob, 7, 1)) AS dmp,
TO_DATE(
TO_CHAR(
(ASCII(SUBSTR(chars, 1, 1)) - 100) * 100
+ ASCII(SUBSTR(chars, 2, 1)) - 100,
'0000'
)
|| TO_CHAR(ASCII(SUBSTR(chars, 3, 1)), '00')
|| TO_CHAR(ASCII(SUBSTR(chars, 4, 1)), '00')
|| TO_CHAR(ASCII(SUBSTR(chars, 5, 1)) - 1, '00')
|| TO_CHAR(ASCII(SUBSTR(chars, 6, 1)) - 1, '00')
|| TO_CHAR(ASCII(SUBSTR(chars, 7, 1)) - 1, '00'),
'YYYYMMDDHH24MISS'
) AS converted_date
FROM (
SELECT file_blob,
UTL_RAW.CAST_TO_VARCHAR2(DBMS_LOB.SUBSTR(file_blob, 7, 1)) AS chars
FROM file_upload
);
Ausgang:
DMP CONVERTED_DATE
------------------------------- -------------------
Typ=23 Len=7: 120,116,3,6,1,1,1 2016-03-06 00:00:00
Genau das, was ich suche, arbeitete wie ein Charme. Danke vielmals. –