0

我在 Oracle 数据库的表中有一个 XML 列,出于某种原因,我意识到 XML 标记最后被破坏了。

<XMLBegin><linesandlinesofXML>blahblahblah</linesandlinesofXML>
<Framework.DesktopContent.ImageLocation ObjectName="PaneContentImageSelected" locati...

我能否知道是否可以在“...”不在标签中的 XML 列中搜索“...”?我想清除损坏的 XML 而不必清除整个表。

提前致谢!

4

1 回答 1

3

如果它的发现和无效的 XMLs,你可以这样做:

SQL> desc myxml
 Name                                      Null?    Type
 ----------------------------------------- -------- --------
 XML                                                CLOB

SQL> create or replace function is_valid(xml clob) return varchar2
  2  is
  3    e_invalid exception;
  4    pragma exception_init(e_invalid, -31011);
  5    v_xml xmltype;
  6  begin
  7    v_xml := xmltype(xml);
  8    return 'Y';
  9  exception
 10    when e_invalid
 11    then
 12      return 'N';
 13  end;
 14  /

Function created.

SQL> select * from myxml;

XML
--------------------------------------------------------------------------------
<XMLBegin><linesandlinesofXML>blahblahblah</linesandlinesofXML>
<Framework.DesktopContent.ImageLocation ObjectName="PaneContentImageSelected" lo
cati..

<XMLBegin><linesandlinesofXML>blahblahblah</linesandlinesofXML></XMLBegin>

SQL> select * from myxml where is_valid(xml) = 'N';

XML
--------------------------------------------------------------------------------
<XMLBegin><linesandlinesofXML>blahblahblah</linesandlinesofXML>
<Framework.DesktopContent.ImageLocation ObjectName="PaneContentImageSelected" lo
cati..
于 2012-11-22T11:52:01.070 回答