看到ORA-01858,发现非数字字符?

时间:2020-02-12 15:44:18

标签: sql oracle

这是针对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: a non-numeric character was found where a numeric was expected error

但是错误没有告诉我在哪里。有什么想法吗?

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

1 个答案:

答案 0 :(得分:1)

这是高度可疑的:

df = pdr.data.get_data_yahoo(ticker, start='2012-01-01', end='2012-10-10')
df = df[['Open', 'High', 'Low', 'Close']]

fig, ax1 = plt.subplots(figsize=(14,7), num='figure name')

ax1.set_title('box title')
ax1.yaxis.grid(True, linestyle='-', which='major', color='lightgrey', alpha=0.5)
ax1.xaxis.grid(True, linestyle='-', which='major', color='lightgrey', alpha=0.5)

bp = ax1.boxplot(df, patch_artist=True, labels=df.index.astype(str))

# green up, red down
for count_box in range(len(df.index)):
    if (df.iloc[count_box,0]-df.iloc[count_box,3])>=0:
       plt.setp(bp['boxes'][count_box], color='red')
    else:
       plt.setp(bp['boxes'][count_box], color='green')

 plt.xticks(rotation=30)
 plt.show() #or plt.savefig()

为什么要将SELECT TO_CHAR(TS, 'DD-MON-YYYY HH AM') AS DATE 转换为字符串以放入称为timestamp的字段中?如果您希望将日期缩短到特定时间,请改用date

TRUNC()

所以:

SELECT TRUNC(TS, 'HH')

我也建议您使用SELECT TRUNC(TS, 'HH') 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, 'HH'), mrch ORDER BY TRUNC(TS, 'HH'), mrch_bnft; 而不是日期算术,但是您的版本实际上很好。