我有一个表,其中有大约一千条记录,其中一列是数据类型CLOB,由于其他原因,我现在必须将其转换为XMLType。 如何将列从CLOB转换为XMLType? 感谢
答案 0 :(得分:0)
您可以尝试这样做:
这样的事情:
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;
答案 1 :(得分:0)
您可以使用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_变量应包含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_);