我正在尝试在Oracle中创建一个XML文档。它应该在顶层有一个序列值,还有一些行级项目。例如,查询在没有行项目的情况下工作
WITH j AS (
SELECT
'abc' test
FROM
dual
GROUP BY
1
)
SELECT
XMLSERIALIZE(DOCUMENT XMLELEMENT(
"WhseSnapshot",
XMLELEMENT(
"mdDC",
MD_EXTRACT_ID_SEQ.NEXTVAL
)
))
FROM
j;
产生输出
<WhseSnapshot><mdDC>157</mdDC></WhseSnapshot>
向查询添加行项目,如下所示
WITH j AS (
SELECT
'abc' test
FROM
dual
GROUP BY
1
)
SELECT
XMLSERIALIZE(DOCUMENT XMLELEMENT(
"WhseSnapshot",
XMLELEMENT(
"mdDC",
MD_EXTRACT_ID_SEQ.NEXTVAL
),
XMLAGG(XMLELEMENT(
"line",
XMLFOREST(j.test AS "test")
))
))
FROM
j;
导致以下错误
ORA-02287: sequence number not allowed here
02287. 00000 - "sequence number not allowed here"
*Cause: The specified sequence number (CURRVAL or NEXTVAL) is inappropriate
here in the statement.
*Action: Remove the sequence number.
Error at Line: 84 Column: 25
有没有人能达到类似的目标?我希望避免PL/SQL块或函数,并尽可能坚持使用常规SQL。
1条答案
按热度按时间4xrmg8kj1#
可以在子查询中聚合表:
其输出:
| XML|
| - -----|
| 1abc|
fiddle