Oracle 将列数据类型从clob更改为xmltype
我有一个表,其中大约有1000条记录,其中一列是数据类型CLOB,由于其他原因,现在我不得不转换为XMLType。 如何将列从CLOB转换为XMLType?Oracle 将列数据类型从clob更改为xmltype,oracle,Oracle,我有一个表,其中大约有1000条记录,其中一列是数据类型CLOB,由于其他原因,现在我不得不转换为XMLType。 如何将列从CLOB转换为XMLType? 谢谢您可以尝试这样做: alter table yourtable add (temp_col xmltype); update yourtable set temp_col = xmltype.createxml(clobCol); alter table yourtable drop column clobCol; alter t
谢谢您可以尝试这样做:
alter table yourtable
add (temp_col xmltype);
update yourtable
set temp_col = xmltype.createxml(clobCol);
alter table yourtable
drop column clobCol;
alter table yourtable
rename column temp_col to clobCol;
alter table yourtable
add (temp_col xmltype);
update yourtable
set temp_col = xmltype.createxml(clobCol);
alter table yourtable
drop column clobCol;
alter table yourtable
rename column temp_col to clobCol;
您可以使用DBMS_XMLPARSER包执行以下操作:
-- Variables used for parsing the XML document
xml_ CLOB := 'X';
p DBMS_XMLPARSER.parser;
doc_ DBMS_XMLDOM.DOMDocument;
node_list_ DBMS_XMLDOM.DOMNodeList;
node_len_ NUMBER;
-- Convert the CLOB into a XML-document enter code here
P := DBMS_XMLPARSER.newparser();
-- Parse the clob and get the XML-document
DBMS_XMLPARSER.parseclob(p, xml_);
-- Note that the document is parsed in local CSID even thought the xml contains UTF8, strange but it seems to work
doc_ := DBMS_XMLPARSER.getDocument(p);
--- Bug 114812 SPM Start
node_list_ := DBMS_XMLDOM.getElementsByTagName(doc_, 'NODETOEXTRACT');
node_len_ := DBMS_XMLDOM.getLength(node_list_);
注意:-xml_uu变量应包含CLOB格式的消息以对其进行解析。如果XML位于BLOB中,则可以使用此方法转换为CLOB
-- Convert the BLOB-message into a CLOB
DBMS_LOB.converttoclob(dest_lob => xml_,
src_blob => message_value_,
amount => dbms_lob.lobmaxsize,
dest_offset => l_dest_offsset_,
src_offset => l_src_offsset_,
blob_csid => 871, -- 871 is UTF8
lang_context => l_lang_context_,
warning => l_warning_);
当我将数据从clob列复制到xmltype列时,它给出了不确定的数据类型错误..update yourtable set temp\u col=clobCol;。。通过此查询..我在xmltype.create(clobcol)中遇到此错误。。。错误报告-SQL错误:ORA-31011:XML解析失败ORA-19202:XML处理中发生错误LPX-00216:第3行ORA-06512处的无效字符7(0x7)错误:第5 31011行的“SYS.XMLTYPE”处。00000-“XML解析失败”*原因:XML解析器在尝试解析文档时返回错误*操作:检查要分析的文档是否有效。看起来一个或多个条目不是格式良好的XML。使用外部XML编辑器进行验证