DB2 检索多次出现的 xml 元素
DB2 retrieving multiple occurrences of a xml element
我刚开始查询 xml。
我有一个 table NOTIFICATIONS,它在属性 CONTENT 中包含一个 xml 字符串。
属性的内容如下所示(格式化):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<interuptionLimitation xmlns="http://example.com/schema">
<person>1000000</person>
<date>2020-07-20</date>
<reason>Contact</reason>
<debtId>1</debtId>
<debtId>2</debtId>
</interuptionLimitation>
debId 可以出现多次
在 DB2 中,我希望输出为:
person date reason debtId
1000000 2020-07-20 Contact 1
1000000 2020-07-20 Contact 2
我有以下查询
SELECT X.*
FROM NOTIFICATIONS n
, XMLTABLE ('$I/interuptionLimitation ' PASSING XMLPARSE(document n.CONTENT) as "I"
COLUMN
"person" bigint PATH 'person',
"date" CHAR(10) PATH 'date',
"reason" VARCHAR(200) PATH 'reason',
"debtId" bigint PATH '@debtId') AS X
不幸的是,这没有输出。
有人可以帮我解决这个问题吗?
试试这个:
/*
WITH NOTIFICATIONS (CONTENT) AS
(
VALUES '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<interuptionLimitation xmlns="http://example.com/schema">
<person>1000000</person>
<date>2020-07-20</date>
<reason>Contact</reason>
<debtId>1</debtId>
<debtId>2</debtId>
</interuptionLimitation>'
)
*/
SELECT X.*
FROM NOTIFICATIONS n
, XMLTABLE
(
XMLNAMESPACES(DEFAULT 'http://example.com/schema'),
'$I/interuptionLimitation/debtId' PASSING XMLPARSE(document n.CONTENT) as "I"
COLUMNS
"person" bigint PATH '../person',
"date" CHAR(10) PATH '../date',
"reason" VARCHAR(200) PATH '../reason',
"debtId" bigint PATH '.'
) AS X;
我刚开始查询 xml。
我有一个 table NOTIFICATIONS,它在属性 CONTENT 中包含一个 xml 字符串。 属性的内容如下所示(格式化):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<interuptionLimitation xmlns="http://example.com/schema">
<person>1000000</person>
<date>2020-07-20</date>
<reason>Contact</reason>
<debtId>1</debtId>
<debtId>2</debtId>
</interuptionLimitation>
debId 可以出现多次
在 DB2 中,我希望输出为:
person date reason debtId
1000000 2020-07-20 Contact 1
1000000 2020-07-20 Contact 2
我有以下查询
SELECT X.*
FROM NOTIFICATIONS n
, XMLTABLE ('$I/interuptionLimitation ' PASSING XMLPARSE(document n.CONTENT) as "I"
COLUMN
"person" bigint PATH 'person',
"date" CHAR(10) PATH 'date',
"reason" VARCHAR(200) PATH 'reason',
"debtId" bigint PATH '@debtId') AS X
不幸的是,这没有输出。
有人可以帮我解决这个问题吗?
试试这个:
/*
WITH NOTIFICATIONS (CONTENT) AS
(
VALUES '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<interuptionLimitation xmlns="http://example.com/schema">
<person>1000000</person>
<date>2020-07-20</date>
<reason>Contact</reason>
<debtId>1</debtId>
<debtId>2</debtId>
</interuptionLimitation>'
)
*/
SELECT X.*
FROM NOTIFICATIONS n
, XMLTABLE
(
XMLNAMESPACES(DEFAULT 'http://example.com/schema'),
'$I/interuptionLimitation/debtId' PASSING XMLPARSE(document n.CONTENT) as "I"
COLUMNS
"person" bigint PATH '../person',
"date" CHAR(10) PATH '../date',
"reason" VARCHAR(200) PATH '../reason',
"debtId" bigint PATH '.'
) AS X;