表创建脚本:
CREATE TABLE "TEST"("INTERVAL_COL" INTERVAL DAY (0) TO SECOND (6));
Insert into TEST (INTERVAL_COL) values ('+00 11:00:24.920000');
Insert into TEST (INTERVAL_COL) values ('+00 11:00:26.890000');
Insert into TEST (INTERVAL_COL) values ('+00 11:00:28.460000');
Insert into TEST (INTERVAL_COL) values ('+00 11:00:30.140000');
Insert into TEST (INTERVAL_COL) values ('+00 11:00:31.790000');
commit;
在SQL Developer和sqlPlus中,运行SELECT * FROM TEST
效果都很好,SELECT INTERVAL_COL FROM TEST
一样。
但是,以下任何一个给我一个错误:
SELECT INTERVAL_COL || '.' FROM TEST
SELECT TO_CHAR(INTERVAL_COL, 'HH24:MM.SS') FROM TEST
错误是:
ORA-01877:对于内部缓冲区,字符串太长
如果要将此day to second
数据转换为HH24:MI:SS
,则可以使用:
TO_CHAR(CAST((TRUNC(SYSTIMESTAMP)+INTERVAL_COL) AS DATE), 'HH24:MI.SS')
也如Alex所评论,
TO_CHAR(TRUNC(SYSDATE)+INTERVAL_COL, 'HH24:MI.SS')
也可以。
REGEXP_REPLACE(REGEXP_SUBSTR(INTERVAL '+00 11:00:24.920000' DAY TO SECOND, '\d{2}:\d{2}:\d{2}'), ':(\d{2})$', '.\1')