我在Oracle数据库的表中有一个XML列,出于某种原因,我意识到XML标记最后都被破坏了。
<XMLBegin><linesandlinesofXML>blahblahblah</linesandlinesofXML>
<Framework.DesktopContent.ImageLocation ObjectName="PaneContentImageSelected" locati...
我是否可以知道是否可以在XML列中搜索“...”,其中“...”不在标签中?我想清除破碎的XML,而不必清除整个表。
提前致谢!
答案 0 :(得分:3)
如果找到它和无效的XML,你可以这样做:
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..