我有这个查询:
SELECT
XMLELEMENT("row", XMLATTRIBUTES(productMain.variant as "order"),
(SELECT XMLELEMENT("attribute", XMLATTRIBUTES(product.id as "id") )
FROM product where product.variant = productMain.variant
)
)
FROM
(SELECT
DISTINCT product.variant
FROM
product
WHERE
product.fk_parent = 12345) productMain
我收到一个错误'invalid identifier productMain.variant
'。
预期结果:
<row order="1">
<attribute name="Example1"/>
<attribute name="Example2"/>
...
</row>
<row order="2">
...
</row>
表product
:
id | variant | name
_________________________
1 | 1 | Example1
2 | 1 | Example2
3 | 2 | Example3
4 | 3 | Example4
5 | 3 | Example5
...
SQLFIDDLE: http ://www.sqlfiddle.com/#!4/e91a6/2
我发现,Oracle 不会关联嵌套超过一层的子查询。
我如何仍然得到我想要的结果?