[英]Getting SQL Error: ORA-01847: day of month must be between 1 and last day of month when running my statment
Guys not sure why I am getting the error in the title. 伙计们不确定我为什么会出现标题错误。 See below, any help one the insert statement below would be much appreciated:
参见下文,对以下插入语句的任何帮助将不胜感激:
thanks in advance 提前致谢
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
I would suggest you to use INTERVAL DAY TO SECOND
for RUN_TIME
instead of TIMESTAMP
我建议您将
INTERVAL DAY TO SECOND
用于RUN_TIME
而不是TIMESTAMP
Also, specify all the column names in the insert. 另外,在插入中指定所有列名称。
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);
Why working with Oracle you should learn two basic things. 为什么使用Oracle,您应该学习两个基本知识。
1) do not rely on the table structure 1)不依赖表结构
2) do not rely on the session or database setting of DATE format 2)不依赖会话或数据库设置的DATE格式
Reason - both can easy be changed and your statement will fail. 原因-两者都可以轻松更改,您的陈述将失败。
You violates both in your INSERT
statement. 您在
INSERT
语句中都违反了两者。
So try this 所以试试这个
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.