我有 2 个 Oracle 11g 数据库,其中一个表包含一个 XMLType 列和一些测试数据,仅在时间戳的毫秒数的分隔符 (.,) 中有所不同:
create table TEST_TIMESTAMP (
ID number(19,0) constraint "NN_TEST_TIMESTAMP_ID" not null,
DOC xmltype constraint "NN_TEST_TIMESTAMP_DOC" not null
);
insert into TEST_TIMESTAMP values ( 1, xmltype('<?xml version="1.0" encoding="utf-8"?><test><ts>2015-04-08T04:55:33.11</ts></test>'));
insert into TEST_TIMESTAMP values ( 2, xmltype('<?xml version="1.0" encoding="utf-8"?><test><ts>2015-04-08T04:55:33,11</ts></test>'));
当我尝试使用以下语句提取时间戳时,它会因一个数据库上的第一个文档或另一个数据库上的第二个文档而失败。
select x.*
from TEST_TIMESTAMP t,
xmltable(
'/test'
passing t.DOC
columns
ORIGINAL varchar2(50) path 'ts',
RESULT timestamp with time zone path 'ts'
) x
where t.ID = 1;
select x.*
from TEST_TIMESTAMP t,
xmltable(
'/test'
passing t.DOC
columns
ORIGINAL varchar2(50) path 'ts',
RESULT timestamp with time zone path 'ts'
) x
where t.ID = 2;
我得到的错误:
ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause: The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action: Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
我发现的这些数据库之间的唯一区别是:
- DB1:版本=11.2.0.1.0,NLS_CHARACTERSET=AL32UTF8 -> 在文档 2 上失败
- DB2:版本=11.2.0.2.0,NLS_CHARACTERSET=WE8MSWIN1252 -> 在文档 1 上失败
DB1 具有我所期望的行为。有谁知道为什么这些数据库的行为不同以及如何解决 DB2 中的问题?
在此先感谢,奥利弗