代码之家  ›  专栏  ›  技术社区  ›  Thelnternet

使用触发器抛出错误:ora-20987:apex-ora-01858 ora-06512

  •  0
  • Thelnternet  · 技术社区  · 6 年前

    我一直在研究一个触发器,它计算修改表时的用户数。

    桌子:

    SKN_ENJIN
    ID            NUMBER
    ENJIN_NAME    VARCHAR2(99)
    EMAIL         VARCHAR2(99)
    IP_ADDRESS    VARCHAR2(15)
    STATUS        NUMBER
    
    
    SKN_ENJIN_COUNT
    ID            NUMBER
    COUNT_DATE    DATE
    MEMBER_COUNT  NUMBER
    

    触发

    create or replace trigger "BI_SKN_ENJIN_COUNT_TG" 
      after insert or update or delete on "SKN_ENJIN"               
    
      DECLARE
      mCount    NUMBER;
      mDate     DATE;
    
    begin 
    
      select COUNT(ID) into mCount from SKN_ENJIN where Status = 1;
    
      select CURRENT_DATE into mDate from dual;
    
      MERGE INTO SKN_ENJIN_COUNT c
          USING (Select * from SKN_ENJIN_COUNT)
          ON (TO_DATE(c.Count_date, 'MM-DD-YYYY') = TO_DATE(mDate, 'MM-DD-YYYY'))
        WHEN MATCHED THEN
          UPDATE SET c.Member_count = mCount
        WHEN NOT MATCHED THEN
          INSERT (Count_date, Member_count)
          VALUES (mDate, mCount);
    end;
    

    当我手动将数据放入对象浏览器时,触发器工作正常。 当我将脚本放入sql命令时,它也可以工作…

    但当我在应用程序中放置相同的数据时,会出现以下错误:

    Ajax call returned server error ORA-20987: APEX - ORA-01858: a non-numeric
    character was found where a numeric was expected ORA-06512: at 
    "SOKAN_MEMBER_DATA.BI_SKN_ENJIN_COUNT_TG", line 11 ORA-04088: error during
    execution of trigger 'SOKAN_MEMBER_DATA.BI_SKN_ENJIN_COUNT_TG' - Contact
    your application administrator. Details about this incident are available
    via debug id "835641798". for .
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Maxim Borunov    6 年前

    不需要对日期变量/列执行到日期的转换。它首先生成到varchar2的隐式会话,然后返回到date。

    尝试简单地截断日期(时间设置为00:00:00)。

    所以不要这样:

    ON (TO_DATE(c.Count_date, 'MM-DD-YYYY') = TO_DATE(mDate, 'MM-DD-YYYY'))
    

    使用此:

    ON (trunc(c.Count_date) = trunc(mDate))