oracle 将 xml 插入 XmlType 字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19664377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert xml into XmlType field
提问by user1945034
I have this table in Oracle 11g:
我在 Oracle 11g 中有这个表:
create table tmp_test_xml (
name_xml varchar2(4000),
file_xml xmltype
);
At this link oracle binding xmltype, I have read that for a correct insert into a field XMLType
I must to use the "Xmltype binding" as this insert:
在这个链接oracle binding xmltype,我已经阅读了正确插入到字段中的内容,XMLType
我必须使用“Xmltype binding”作为这个插入:
insert into tmp_test_xml values (
'file.xml',
xmltype(
'<?xml version="1.0" encoding="UTF-8"?>
<list_book>
<book>1</book>
<book>2</book>
<book>3</book>
</list_book>'
)
);
But, if I try to lunch this insert without the binding in XMLType
, work very fine:
但是,如果我尝试在没有绑定 in 的情况下使用这个插入XMLType
,工作得很好:
insert into tmp_test_xml values (
'file.xml',
'<?xml version="1.0" encoding="UTF-8"?>
<list_book>
<book>1</book>
<book>2</book>
<book>3</book>
</list_book>'
);
Now, is facoltative use binding or not? What is the correct insert?
现在,兼性使用是否具有约束力?什么是正确的插入?
Why the second insert works?
为什么第二个插入有效?
采纳答案by Nagh
Oracle tries to do job for you, so if your datatype doesn't match column datatype, it attempts to convert data into correct data type.
Oracle 尝试为您完成工作,因此如果您的数据类型与列数据类型不匹配,它会尝试将数据转换为正确的数据类型。
Since you have correct xml string in your insert statement, database did conversion to xmltype for you.
由于您的插入语句中有正确的 xml 字符串,因此数据库会为您转换为 xmltype。
And I'm not sure, but I doubt there were a word mustuse XMLType binding.
But you might want use it, if you need to have more control when creating XML from string.
Check XMLType constructorsto get an idea.
而且我不确定,但我怀疑是否有一个词必须使用 XMLType 绑定。
但是,如果在从字符串创建 XML 时需要更多控制,您可能想要使用它。
检查XMLType 构造函数以获得一个想法。