出现SQL错误:ORA-01847:运行我的报表时,每月的某天必须在1到该月的最后一天之间

时间:2018-07-21 10:58:39

标签: database oracle

不确定我为什么会出现标题错误。参见下文,对以下插入语句的任何帮助将不胜感激:

预先感谢

INSERT INTO RUN_DATA VALUES ('15-JUL-18','5.00K','64:00','233','6','6','17.13','0')
Error report -
SQL Error: ORA-01847: day of month must be between 1 and last day of month
01847. 00000 -  "day of month must be between 1 and last day of month"
*Cause:    
*Action:


Name             Null Type         
---------------- ---- ------------ 
RUN_DATE              DATE         
RUN                   VARCHAR2(8)  
RUN_TIME              TIMESTAMP(6) 
CALORIES              NUMBER(4)    
SITUPS                NUMBER(3)    
PRESSUPS              NUMBER(3)    
WEIGHT                NUMBER(4,2)  
WEIGHT_LOSS_GAIN      NUMBER(2) 

PARAMETER                      VALUE                                                          
------------------------------ ----------------------------------------------------------------
NLS_DATE_FORMAT                DD-MON-RR                          

SYSDATE 
---------
21-JUL-18

2 个答案:

答案 0 :(得分:2)

我建议您为INTERVAL DAY TO SECOND使用RUN_TIME而不是TIMESTAMP

此外,在插入中指定所有列名称。

CREATE TABLE RUN_DATA (
RUN_DATE              DATE    ,     
RUN                   VARCHAR2(8) , 
RUN_TIME              INTERVAL DAY TO SECOND ,
CALORIES              NUMBER(4)    ,
SITUPS                NUMBER(3)    ,
PRESSUPS              NUMBER(3)    ,
WEIGHT                NUMBER(4,2)  ,
WEIGHT_LOSS_GAIN      NUMBER(2) 
  );

ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-RR'; --alternatively use DATE literal or TO_DATE


INSERT INTO run_data 
            (run_date, 
             run, 
             run_time, 
             calories, 
             situps, 
             pressups, 
             weight, 
             weight_loss_gain) 
VALUES      ('15-JUL-18', --or DATE '2018-07-15'
             '5.00K', 
             interval '64' minute,  --specifying proper interval
             233, 
             6, 
             6,      --quotes not needed for number types
             17.13, 
             0); 

Demo

答案 1 :(得分:1)

为什么要使用Oracle,您应该学习两个基本知识。

1)不依赖表结构

2)不依赖于DATE格式的会话或数据库设置

原因-两者都可以轻松更改,您的陈述将失败。

您同时违反了INSERT声明。

所以试试这个

INSERT INTO RUN_DATA 
(RUN_DATE,RUN,RUN_TIME,CALORIES,SITUPS ,PRESSUPS,WEIGHT,WEIGHT_LOSS_GAIN)
VALUES (to_date('15.06.2018','dd.mm.yyyy'), -- define explicite DATE format
--- alternative use DATE literal  DATE'2018-06-15'
'5.00K',
TIMESTAMP '2018-01-31 09:26:50.124',   -- TIMESTAMP literal
'233','6','6','17.13','0')