我想使用 sql 从具有列 testclob 的表 TRAPTABCLOB 中提取 Decision 的值,其中 XML 存储为 clob。 在 DB2 中
XML 示例如下
<?xml version="1.0" encoding="UTF-8"?>
<DCResponse>
<Status>Success</Status>
<Authentication>
<Status>Success</Status>
</Authentication>
<ResponseInfo>
<ApplicationId>5701200</ApplicationId>
<SolutionSetInstanceId>
63a5c214-b5b5-4c45-9f1e-b839a0409c24
</SolutionSetInstanceId>
<CurrentQueue />
</ResponseInfo>
<ContextData>
<!--Decision Details Start-->
<Field key="SoftDecision">A</Field>
<Field key="**Decision**">1</Field>
<Field key="NodeNo">402</Field>
<Field key="NodeDescription" />
<!--Decision Details End-->
<!--Error Details Start-->
<Field key="ErrorResponse">
<Response>
<Status>[STATUS]</Status>
<ErrorCode>[ERRORCODE]</ErrorCode>
<ErrorDescription>[ERRORDESCRIPTION]</ErrorDescription>
<Segment>[SEGMENT]</Segment>
</Response>
</Field>
<Field key="ErrorCode">0</Field>
<Field key="ErrorDescription" />
</ContextData>
</DCResponse>
最佳答案
使用 XMLTABLE() 的好处之一是它生成的表达式可以用作子查询或连接到表或另一个 SQL 表达式。
SELECT x.decision
FROM traptabclob, XMLTABLE(
'$d/DCResponse/ContextData[1]' PASSING XMLPARSE(DOCUMENT testclob) AS "d"
COLUMNS
DECISION CHAR(1) PATH 'Field[@key="**Decision**"][1]'
) AS x
;
关于sql - 使用来自 db2 的 SQL 从 XML Clob 中提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20618941/