甲骨文版本:
这个查询的结果select * from v$version;
是:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
"CORE 11.2.0.4.0 Production"
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
我的情况介绍:
我正在使用我的过程创建一个大型 xmltype,并将其插入到我的表中。然后,我尝试针对已在数据库中注册的 .xsd 验证创建的 xmltype 文件。我已经成功地缩短了 xmltype 数据和 .xsd 文件,因此我可以准确地向您展示 .xml 文件内的哪一行我遇到了问题。
我准备的代码你可以复制粘贴进行测试:
这是我的简单表:
create table XML_DATE_TEST(
xml_file xmltype
);
创建 xmltype 数据并将其插入此表的过程如下:
CREATE OR REPLACE PROCEDURE P_XML_DATE_TEST (p_testvar in number) --
IS
xml_help_variable xmltype;
BEGIN
SELECT XMLELEMENT
("DocumentROOTTag",
XMLATTRIBUTES(
'http://www.w3.org/2001/XMLSchema-instance' "xmlns:xsi"
, 'XSD_TEST.xsd' "xsi:noNamespaceSchemaLocation"),
XMLELEMENT
("SomeDateTag",
(to_char( sysdate,'yyyy-mm-dd')||'T'||to_char( sysdate,'hh24:mi:ss')||'Z'))
)
INTO xml_help_variable
FROM dual
WHERE p_testvar = 2;
INSERT INTO XML_DATE_TEST VALUES (xml_help_variable);
END P_XML_DATE_TEST;
然后我像这样注册我的 .xsd 架构:
BEGIN
DECLARE
l_schema CLOB;
BEGIN
l_schema := '<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2009 sp1 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DocumentROOTTag">
<xs:complexType>
<xs:sequence>
<xs:element ref="SomeDateTag"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="SomeDateTag">
<xs:simpleType>
<xs:restriction base="xs:dateTime"/>
</xs:simpleType>
</xs:element>
</xs:schema>';
DBMS_XMLSCHEMA.registerSchema(schemaurl => 'XSD_TEST.xsd',
schemadoc => l_schema,
local => TRUE,
gentypes => FALSE,
gentables => FALSE,
enablehierarchy => DBMS_XMLSCHEMA.enable_hierarchy_none);
END;
END;
然后我调用我的程序:
BEGIN
P_XML_DATE_TEST(2);
END;
毕竟,我去尝试根据我注册的 .xsd 文件验证表中创建的 xmltype 数据。我尝试通过两种方式做到这一点:
1.通过使用isSchemaValid
SELECT x.xml_file.isSchemaValid('XSD_TEST.xsd')
FROM XML_DATE_TEST x;
2.通过使用schemaValidate
BEGIN
DECLARE
XML XMLTYPE;
BEGIN
select x.xml_file.createSchemaBasedXML('XSD_TEST.xsd')
INTO XML
from XML_DATE_TEST X;
xmltype.schemaValidate(XML);
END;
END;
问题:
使用我使用的第一个方法(isSchemaValid),我得到的结果是 1。这意味着当我根据提供的 .xsd 模式验证它时,我的 xmltype 数据是正确的。使用我使用的第二种方法(schemaValidate),我得到的结果是一个错误:
Error report -
ORA-30992: error occurred at Xpath /DocumentROOTTag/SomeDateTag
ORA-01830: date format picture ends before converting entire input string
ORA-06512: at "SYS.XMLTYPE", line 354
ORA-06512: at line 9
30992. 00000 - "error occurred at Xpath %s"
*Cause:
*Action: See the following error and take appropriate action.
我试过的:
当我从日期格式中删除“Z”部分时,一切正常,但这不是一个适合我的解决方案。日期的格式必须和现在一样。