小编典典

看到ORA-01858:在需要数字的地方找到了非数字字符

sql

以下是我对Oracle SQL Developer的查询:

INSERT INTO ENROLLMENTS (DATE,PARTNER_NAME,ENROLLMENTS)
    SELECT TO_CHAR(TS, 'DD-MON-YYYY HH AM') AS DATE, mrch_bnft_cd, COUNT(*)
    FROM ENROLLMENTS 
    WHERE TS > trunc(sysdate-1/24, 'HH') + 5/24 
    AND TS < trunc(sysdate, 'HH') + 5/24
    GROUP BY TO_CHAR(TS, 'DD-MON-YYYY HH AM'), mrch
    ORDER BY TO_CHAR(TS, 'DD-MON-YYYY HH AM'), mrch_bnft

我得到一个错误

ORA-01858:在非预期的数字位置发现了一个非数字字符

但是错误并没有告诉我在哪里。有任何想法吗?

DATE = TIMESTAMP(6)
TS = TIMESTAMP(6)  
PARTNER = VARCHAR2(35 BYTE)  
ENROLLMENTS = NUMBER  
MRCH_BNFT= VARCHAR2(35 BYTE)

阅读 822

收藏
2021-04-15

共1个答案

小编典典

基本上,您尝试在时间戳字段中存储代表日期的字符串。如果您更换:

TO_CHAR(TS, 'DD-MON-YYYY HH AM')

经过

TRUNC(TS, 'hh24')

在所有4个地方都应该起作用。

INSERT INTO ENROLLMENTS (DATE,PARTNER_NAME,ENROLLMENTS)
    SELECT   TRUNC(TS, 'hh24') AS DATE, mrch_bnft_cd, COUNT(*)
    FROM     ENROLLMENTS 
    WHERE    TS > trunc(sysdate-1/24, 'HH') + 5/24 
    AND      TS < trunc(sysdate, 'HH') + 5/24
    GROUP BY TRUNC(TS, 'hh24'), mrch
    ORDER BY TRUNC(TS, 'hh24'), mrch_bnft
2021-04-15