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, 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
I get an error
ORA-01858: a non-numeric character was found where a numeric was expected error
but the error is not telling me where. Any ideas?
DATE = TIMESTAMP(6)
TS = TIMESTAMP(6)
PARTNER = VARCHAR2(35 BYTE)
ENROLLMENTS = NUMBER
MRCH_BNFT= VARCHAR2(35 BYTE)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.