当我运行下面的插入命令时,我收到ORA-01843。我的代码有问题吗?并得到以下错误消息:
SQL错误:
ORA-01843: not a valid month
ORA-06512: at "MDSYS.SUPERHEROES_AUDIT", line 8
ORA-04088: error during execution of trigger 'MDSYS.SUPERHEROES_AUDIT'
01843. 00000 - "not a valid month"
我的声明似乎有什么问题?谢谢。
/* TABLE CREATED */
CREATE TABLE EVENTLOGS(
Eventlog_id Number(3,0) NOT NULL,
User_name Varchar2(20),
Date_done Date,
Action_done Varchar2(50),
CONSTRAINT PK_EVENTLOGS PRIMARY KEY (Eventlog_id));
/* SEQUENCE CREATED */
CREATE SEQUENCE EVENTLOG_ID_SEQ
MINVALUE 1
START WITH 1
INCREMENT BY 1
NOCYCLE
CACHE 10;
/* TRIGGER CREATED */
CREATE OR REPLACE TRIGGER SUPERHEROES_AUDIT
AFTER INSERT OR DELETE OR UPDATE ON SUPERHEROES
FOR EACH ROW
ENABLE
DECLARE
V_LOGID NUMBER;
V_USER VARCHAR(30);
V_DATE VARCHAR(30);
BEGIN
SELECT EVENTLOG_ID_SEQ.NEXTVAL, USER, TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') INTO V_LOGID, V_USER, V_DATE FROM DUAL;
IF INSERTING THEN
INSERT INTO EVENTLOGS(Eventlog_id, User_name, Date_done, Action_done)
VALUES (V_LOGID, V_USER, V_DATE, 'INSERT');
END IF;
END;
/
INSERT INTO SUPERHEROES VALUES ('TEST');
答案 0 :(得分:0)
表格中的列定义为
Date_done Date,
您将日期存储到VARCHAR2
变量
V_DATE VARCHAR(30);
....
SELECT EVENTLOG_ID_SEQ.NEXTVAL, USER,
TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') INTO V_LOGID, V_USER, V_DATE
...
您正在将此变量插入DATE
列。
...
VALUES (V_LOGID, V_USER, V_DATE, 'INSERT');
保持datatype
一致以避免混淆。