[英]Select on CLOB XML DB2
I have this data as CLOB
field in DB2. 我将此数据作为DB2中的
CLOB
字段。 I am converting the data to char
using cast: 我正在使用强制转换将数据转换为
char
:
SELECT CAST(CLOBColumn as VARCHAR(32000))
FROM Schema.MyTable;
Here is how the result XML comes out from the above: 以下是结果XML如何从上面得出:
<TreeList TreeNo="ABC">
<Tree ErrorCode="INVALID_TREE" ErrorDescription="Tree doesn’t exist." TreeID="123456"/>
<Tree ErrorCode="INVALID_TREE" ErrorDescription="Tree doesn’t exist." TreeID="1234567"/>
</TreeList>
And this is how I expect my output 这就是我对输出的期望
|TreeNo | TreeID | ErrorCode | ErrorDescription
|ABC | 123456 | INVALID_TREE | Tree doesn’t exist
|ABC | 1234567 | INVALID_TREE | Tree doesn’t exist
How do I achieve this? 我该如何实现这一目标?
You need to use the XMLTABLE function which allows to map XML data to a table. 您需要使用XMLTABLE函数 ,该函数允许将XML数据映射到表。 You can pass in XML-typed data and it works if you directly parse the CLOB to XML.
您可以传入XML类型的数据,如果直接将CLOB解析为XML,它就可以工作。 The SELECT would look like the following (you get the idea):
SELECT将如下所示(您明白了):
SELECT x.*
FROM schema.mytable, XMLTABLE(
'$CLOBColumn/TreeList'
COLUMNS
TreeNo VARCHAR(10) PATH '@TreeNo',
TreeID INT PATH 'Tree[@TreeID]',
...
) AS x
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.