我在Oracle中有一个问题,有一个虚拟列(我需要从日期列开始的时间戳);这是我的例子:
CREATE TABLE TBDATETIME(
DATETIME_1 DATE,
DATETIME_2 TIMESTAMP(9) GENERATED ALWAYS AS (
CAST( TO_CHAR(DATETIME_1, 'DD/MM/YYYY HH24:MI:SS')
|| '.' || TO_CHAR(DATETIME_1, 'FF9') AS TIMESTAMP(9))
) VIRTUAL
);
INSERT INTO TBDATETIME(DATETIME_1)
VALUES(SYSDATE);
COMMIT;
SELECT *
FROM TBDATETIME;
ORA-01821: date format not recognized
01821. 00000 - "date format not recognized"
*Cause:
*Action:
获取数据的问题在哪里?我尝试了很多格式面具,但没有任何帮助...
答案 0 :(得分:4)
DATETIME_1 DATE
TO_CHAR(DATETIME_1, 'FF9')
这就是问题 - DATE没有分数秒
将char转换为时间戳会很危险(结果取决于nls设置)
我想你想要这个:
CREATE TABLE TBDATETIME(DATETIME_1 DATE, DATETIME_2 TIMESTAMP(9) GENERATED ALWAYS AS (CAST(DATETIME_1 AS TIMESTAMP(9))) VIRTUAL);