得到多项序列
got multi-item sequence
我的意图是"select the data where container number is equals to input data"(一种搜索功能)。我在尝试检索数据时遇到问题,条件是:
d:goodsShipments/d:consignment/d:transportEquipment/d:id/text()
这里我得到了多个数据。不知道where条件怎么迭代。
我的查询是:
我的消息来源 XML 是:
我如何select sealId 为 5678 的所有声明?
这种情况下如何处理where条件?
您每批货物有多个集装箱,并且您在从原始 XML 中提取后基于 LRN 进行过滤;所以你需要使用嵌套的 XMLTable 对象。第一个从报关单中获取数据并将货物提取为子XML类型。然后将其传递给第二个 XML 提取容器信息的表。
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 将其保存在单个 XML表中,但我认为这样更清楚。
您可以使用以下查询来迭代并从容器组件中获取 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';
我的意图是"select the data where container number is equals to input data"(一种搜索功能)。我在尝试检索数据时遇到问题,条件是:
d:goodsShipments/d:consignment/d:transportEquipment/d:id/text()
这里我得到了多个数据。不知道where条件怎么迭代。
我的查询是:
我的消息来源 XML 是:
我如何select sealId 为 5678 的所有声明? 这种情况下如何处理where条件?
您每批货物有多个集装箱,并且您在从原始 XML 中提取后基于 LRN 进行过滤;所以你需要使用嵌套的 XMLTable 对象。第一个从报关单中获取数据并将货物提取为子XML类型。然后将其传递给第二个 XML 提取容器信息的表。
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 将其保存在单个 XML表中,但我认为这样更清楚。
您可以使用以下查询来迭代并从容器组件中获取 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';