我有下面提到的格式的数据,当我试图插入表格时我收到错误
ORA-01858: a non-numeric character was found where a numeric was expected
如何成功将记录插入表格?
create table mytab (dt timestamp(0));
Insert into mytab
(dt)
Values
(TO_TIMESTAMP('16/JUL/13 2:53:08. PM','DD/MON/YY fmHH12fm:MI:SS.FF AM'));
答案 0 :(得分:3)
您需要指定零小数秒。这是你的错误:
SQL> create table mytab (dt timestamp(0));
Table created.
SQL> Insert into mytab
(dt)
Values
(TO_TIMESTAMP('16/JUL/13 2:53:08. PM','DD/MON/YY fmHH12fm:MI:SS.FF AM')); 2 3 4
(TO_TIMESTAMP('16/JUL/13 2:53:08. PM','DD/MON/YY fmHH12fm:MI:SS.FF AM'))
*
ERROR at line 4:
ORA-01858: a non-numeric character was found where a numeric was expected
SQL>
让我们修复输入
SQL> ed
Wrote file afiedt.buf
1 Insert into mytab
2 (dt)
3 Values
4* (TO_TIMESTAMP('16/JUL/13 2:53:08.00 PM','DD/MON/YY fmHH12fm:MI:SS.FF AM'))
SQL> r
1 Insert into mytab
2 (dt)
3 Values
4* (TO_TIMESTAMP('16/JUL/13 2:53:08.00 PM','DD/MON/YY fmHH12fm:MI:SS.FF AM'))
1 row created.
SQL>
因此,即使您指定了零精度的时间戳,您的输入仍需要与掩码匹配。这意味着您需要.00
来匹配.FF
。
或者,不要费心包括小数秒:
SQL> ed
Wrote file afiedt.buf
1 insert into mytab
2 (dt)
3 Values
4* (TO_TIMESTAMP('16/JUL/13 2:53:08 PM','DD/MON/YY fmHH12fm:MI:SS AM'))
SQL> r
1 insert into mytab
2 (dt)
3 Values
4* (TO_TIMESTAMP('16/JUL/13 2:53:08 PM','DD/MON/YY fmHH12fm:MI:SS AM'))
1 row created.
SQL>
顺便说一句,请注意TIMESTAMP(0)将绕过任何小数秒,在半秒内向上舍入。这是否重要取决于您将如何填充列以及需要准确的时间。
答案 1 :(得分:2)
你需要第二部分:
Insert into mytab(dt)
Values
(TO_TIMESTAMP('16/JUL/13 2:53:08.00 PM','DD/MON/YY fmHH12fm:MI:SS.FF AM'));
答案 2 :(得分:1)
你有一个“。”分钟后
这是有效的
select TO_TIMESTAMP('16/JUL/13 2:53:08 PM','DD/MON/YY fmHH12fm:MI:SS.FF AM')
from dual