Seeing ORA-01858: a non-numeric character was found where a numeric was expected

后端 未结 1 2021
心在旅途
心在旅途 2021-01-29 14:06

The following is my query for Oracle SQL Developer:

INSERT INTO ENROLLMENTS (DATE,PARTNER_NAME,ENROLLMENTS)
    SELECT TO_CHAR(TS, \'DD-MON-YYYY HH AM\') AS DATE         


        
1条回答
  •  有刺的猬
    2021-01-29 14:31

    Basically you are trying to store a string which represents a date in a timestamp field. If you replace:

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

    by

    TRUNC(TS, 'hh24')
    

    at all 4 places it should work.

    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
    

    0 讨论(0)
提交回复
热议问题