我有一个像这样的xml存储在表中:
<xml>
<attribute>name</attribute>
<value>this is my xml</value>
<logLocation>/user/apps/myLogFolder</logLocation>
<engines>
<engine>
<engineName>Engine1</engineName>
<engineLocation>$HOME/apps/engines</engineLocation>
<engineVersion>3.1416</engineVersion>
</engine>
<engine>
<engineName>Engine2</engineName>
<engineLocation>$HOME/apps/engines/backup</engineLocation>
<engineVersion>3b</engineVersion>
</engine>
</engines>
<connections>
<connection>
<jdbc>jdbc:db2://127.0.0.1:50000/localdb</jdbc>
<user>dbuser</user>
<password>{}</password>
</connection>
</connections>
</xml>
该表具有以下结构:
id | xmlText |
(integer) | (clob) |
---------- | -------------- |
1 | [clob] |
2 | [clob] |
---------- | -------------- |
所述xmls存储在每个clob列中。
我要做的是搜索一个值,然后将其与常规表连接。
我想要实现的查询是这样的:
select
t1.*,
xmlValues.logLocation
from
schema.table t1,
(
XMLTABLE
(
SELECT
id,
xmlserialize(xmltext AS VARCHAR(3000)) as xmlValues
FROM
schema.myXMLTable
WHERE
id = t1.id
FETCH FIRST ROW ONLY
)
) xmlValues
where
t1.id = 1;
由于我将在其他代码中使用此查询,因此无法访问DB2控制台。
我怎样才能实现它?
感谢。
答案 0 :(得分:0)
感谢:
Extract data from XML Clob using SQL from db2
我能够得到这个:
select
myJoinTable.objectName,
myJoinTable.objectType,
xmlTableValues.jdbcString,
xmlTableValues.logPath
from
myJoinTable,
(
SELECT
tb1.id as id
xmlField.jdbcString as jdbcString,
xmlField.logPath as logPath
FROM myTable tb1,
XMLTABLE(
'$xmlDoc/xml/connections' PASSING XMLPARSE(DOCUMENT tb1.xmlText) AS "xmlDoc"
COLUMNS
jdbcString varchar(200) PATH 'connection[1]/jdbc',
logPath varchar(500) PATH '../logLocation'
) AS xmlField
) xmlValuesTable
) xmlTableValues
where
myJoinTable.objectID = X
and
myJoinTable.objectID = xmlTableValues.id;
这使我可以查询我需要的内容。
感谢。