SQL错误:ORA-01843:不是有效月份

时间:2017-10-12 04:34:32

标签: oracle plsql oracle11g ora-06512 ora-01843

当我运行下面的插入命令时,我收到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');

1 个答案:

答案 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一致以避免混淆。