我是PL / SQL的新手,已获得了此任务。我有存储在Receive_XML表中的XML消息,其字段名称为XML_DATA。在发送位置发送拆分序列时出现了问题,这导致它们在收到拆分序列时遇到问题。拆分序列是我们接收序列#1,然后接收序列#2,然后再次接收序列#1的地方。
在Receive_XML表中进行搜索以找到实例的最佳方法是什么,在该实例中任何序列都重复多次而不知道序列号。这是我们收到的XML记录的示例。
<MESSAGE>
<HEADER>
<MESSAGE_TYPE>ProductionSequence</MESSAGE_TYPE>
<TIMESTAMP>2019-10-29 10:00:01</TIMESTAMP>
</HEADER>
<PRODUCTION_SEQUENCE>
<SEQUENCES>
<SEQUENCE SEQUENCE_ID="8764 " SEQUENCE_ID_PARENT="">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
<SEQUENCE SEQUENCE_ID="6452 " SEQUENCE_ID_PARENT="8764">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
<SEQUENCE SEQUENCE_ID="8764 " SEQUENCE_ID_PARENT="6452">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
</SEQUENCES>
</PRODUCTION_SEQUENCE>
</MESSAGE>
感谢您提供的任何帮助。
账单
我最后发现对我有用的是:
select SEQUENCE_ID, count(SEQUENCE_ID) Counter
from (
select SEQUENCE_ID
from Receive_XML tbl,
xmltable('/MESSAGE/PRODUCTION_SEQUENCE/SEQUENCES/SEQUENCE'
PASSING xmltype(tbl.xml_data)
COLUMNS SEQUENCE_ID VARCHAR2(30) PATH '@SEQUENCE_ID')
where tbl.id = 4451
) rs
group by SEQUENCE_ID;
答案 0 :(得分:1)
此示例xpath似乎有效:
with Receive_XML as (
select xmltype('
<MESSAGE>
<HEADER>
<MESSAGE_TYPE>ProductionSequence</MESSAGE_TYPE>
<TIMESTAMP>2019-10-29 10:00:01</TIMESTAMP>
</HEADER>
<PRODUCTION_SEQUENCE>
<SEQUENCES>
<SEQUENCE SEQUENCE_ID="8764 " SEQUENCE_ID_PARENT="">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
<SEQUENCE SEQUENCE_ID="6452 "
SEQUENCE_ID_PARENT="8764">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
<SEQUENCE SEQUENCE_ID="8764 "
SEQUENCE_ID_PARENT="6452">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
<SEQUENCE SEQUENCE_ID="6452 " SEQUENCE_ID_PARENT="8764">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
</SEQUENCES>
</PRODUCTION_SEQUENCE>
</MESSAGE>
') XML_DATA from dual )
select
xt.dup
FROM Receive_XML xt,
XMLTABLE('//SEQUENCE'
PASSING xt.xml_data
COLUMNS
dup VARCHAR2(20) PATH '@SEQUENCE_ID[.= ../preceding-sibling::SEQUENCE/@SEQUENCE_ID]'
) xt
where dup is not null
答案 1 :(得分:1)
请尝试以下 PL / SQL 。它计数@SEQUENCE_ID属性。因此,大于1的值表示它是重复项。
PL / SQL
CREATE TABLE tbl (ID INT, xml_data XMLType);
INSERT INTO tbl (ID, xml_data)
VALUES
(1, '<MESSAGE>
<HEADER>
<MESSAGE_TYPE>ProductionSequence</MESSAGE_TYPE>
<TIMESTAMP>2019-10-29 10:00:01</TIMESTAMP>
</HEADER>
<PRODUCTION_SEQUENCE>
<SEQUENCES>
<SEQUENCE SEQUENCE_ID="8764 " SEQUENCE_ID_PARENT="">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
<SEQUENCE SEQUENCE_ID="6452 " SEQUENCE_ID_PARENT="8764">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
<SEQUENCE SEQUENCE_ID="8764 " SEQUENCE_ID_PARENT="6452">
<PIECE_GROUPS>
<PIECE_GROUP>
<PIECE>
<PIECE_ID>514236947</PIECE_ID>
</PIECE>
<PIECE>
<PIECE_ID>578645897</PIECE_ID>
</PIECE>
</PIECE_GROUP>
</PIECE_GROUPS>
</SEQUENCE>
</SEQUENCES>
</PRODUCTION_SEQUENCE>
</MESSAGE>');
select ID, SEQUENCE_ID, count(SEQUENCE_ID) Counter
from (
select ID, SEQUENCE_ID
from tbl,
xmltable('/MESSAGE/PRODUCTION_SEQUENCE/SEQUENCES/SEQUENCE'
PASSING tbl.xml_data
COLUMNS SEQUENCE_ID VARCHAR2(30) PATH '@SEQUENCE_ID')
) rs
group by ID, SEQUENCE_ID;
输出
+----+-------------+---------+
| ID | SEQUENCE_ID | Counter |
+----+-------------+---------+
| 1 | 6452 | 1 |
| 1 | 8764 | 2 |
+----+-------------+---------+