0

我有下面提到的格式的数据,当我尝试插入表格时出现错误

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')); 
4

3 回答 3

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) 将四舍五入任何小数秒,在半秒处四舍五入。这是否重要取决于您将如何填充列以及时间需要有多准确。

于 2013-07-24T10:15:17.937 回答
2

你需要第二个分数:

Insert into mytab(dt)
 Values
    (TO_TIMESTAMP('16/JUL/13 2:53:08.00 PM','DD/MON/YY fmHH12fm:MI:SS.FF AM')); 
于 2013-07-24T10:14:45.873 回答
1

你有一个 ”。” 几分钟后

这行得通

select TO_TIMESTAMP('16/JUL/13 2:53:08 PM','DD/MON/YY fmHH12fm:MI:SS.FF AM') 
from dual
于 2013-07-24T10:14:26.597 回答