Extract specific value from CLOB (containing XML) while creating one delimited string per row of a table. CLOB value may be null on some rows

╄→尐↘猪︶ㄣ 提交于 2019-12-01 16:50:40

the reason for your error by the way is that the xmltype constructor is flawed with null lobs. Personally i always use xmltype.createxml(item_txt) instead. you will find it works as well without having to worry about nvl etc.

Try using nvl:

SELECT 'Item%#'|| Item_ID ||'%#'|| Item_STAT_CD ||'%#'|| 
EXTRACT(XMLTYPE(nvl(Item_TXT, '<OuterTag><InnerTag/></OuterTag>')), '//OuterTag/InnerTag/text()').getStringVal()
FROM Item;

Here is a sqlfiddle demo

Or you can use a CASE statement :

SELECT 'Item%#'|| Item_ID ||'%#'|| Item_CD||'%#'||
case when Item_TXT is not null then
EXTRACT(XMLTYPE(Item_TXT), '//OuterTag/InnerTag/text()').getStringVal() end
FROM Item;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!