我的意图是“选择容器编号等于输入数据的数据”(搜索功能的种类)。当我尝试检索数据时,我遇到了一个问题,问题出现在哪里:
d:goodsShipments/d:consignment/d:transportEquipment/d:id/text()
这里我收到了多个数据。我不知道如何在where条件下迭代它。
我的查询是:
我的源XML是:
如何选择sealId为5678的所有声明? 在这种情况下如何处理where条件?
答案 0 :(得分:3)
每个货物有多个容器,并且在从原始XML中提取后,您将基于LRN进行过滤;所以你需要使用嵌套的XMLTable对象。第一个从声明中获取数据并将货物提取为子XMLType。然后将其传递给第二个XMLTable,它提取容器信息。
SELECT x1.lrn, x1.username, x2.containerNumber
FROM dmsimport_decl d
CROSS JOIN XMLTable(
XMLNAMESPACES(DEFAULT 'http://www.xxxx.invalid/xxxx/xxx/schema/xxx',
'http://www.xxxx.invalid/xxx/schema/common' AS "c",
'http://www.xxxx.invalid/xxxx/xxx/schema/xxx' AS "d"),
'/d:declaration'
PASSING d.object_value
COLUMNS
lrn VARCHAR2(35 CHAR)
PATH 'c:declarationHeader/c:localReferenceNumber/text()',
username CHAR(25)
PATH 'c:declarationHeader/c:username/text()',
consignment XMLType
PATH 'd:goodsShipments/d:consignment'
) x1
CROSS JOIN XMLTable(
XMLNAMESPACES(DEFAULT 'http://www.xxxx.invalid/xxxx/xxx/schema/xxx',
'http://www.xxxx.invalid/xxx/schema/common' AS "c",
'http://www.xxxx.invalid/xxxx/xxx/schema/xxx' AS "d"),
'//d:transportEquipment'
PASSING x1.consignment
COLUMNS
containerNumber VARCHAR2(35 CHAR)
PATH 'd:id/text()'
) x2
WHERE x1.lrn = 'NLDMS111111150010950';
使用您的(更新的)示例XML,生成:
LRN USERNAME CONTAINERNUMBER
----------------------------------- ------------------------- -----------------------------------
NLDMS111111150010950 testSC testSC abcd
NLDMS111111150010950 testSC testSC bcde
NLDMS111111150010950 testSC testSC cdef
NLDMS111111150010950 testSC testSC defg
NLDMS111111150010950 testSC testSC efgh
希望这就是你想要看到的。
您也可以使用更复杂的XPath将其保存在单个XMLTable中,但我认为这更清楚。
答案 1 :(得分:0)
您可以使用以下查询来迭代并从容器组件中获取ID ..
SELECT x1.lrn, x1.username, x2.containerNumber
FROM dmsimport_decl d
CROSS JOIN XMLTable(
XMLNAMESPACES(DEFAULT 'http://www.SSSSSSS/dmsimport',
'http://www.SSSSSSScommon' AS "c",
'http://www.SSSSSSSS/dmsimport' AS "d"),
'/d:declaration'
PASSING d.object_value
COLUMNS
lrn VARCHAR2(35 CHAR)
PATH 'c:declarationHeader/c:localReferenceNumber/text()',
username CHAR(25)
PATH 'c:declarationHeader/c:username/text()',
containerComponent XMLType
PATH 'd:goodsShipments/d:goodsItems'
) x1.
CROSS JOIN XMLTable(
XMLNAMESPACES(DEFAULT 'http://www.SSSSSSSSS/dmsimport',
'http://www.SSSSSS/common' AS "c",
'http://www.SSSSSSSS/dmsimport' AS "d"),
'//d:containerComponent'
PASSING x1.containerComponent
COLUMNS
containerNumber VARCHAR2(35 CHAR)
PATH 'd:id/text()'
) x2
WHERE x1.lrn = 'NL123456789160000464';