当我跑步时
SELECT XMLElement("product",
XMLAttributes(fp.col2 AS "attr2",fp.col4 as "attr4",fp.col5 as "attr5",fp.col6 as "attr6")
XMLElement(SELECT (XMLElement("dataset",
XMLAttributes(ds.col3 AS "attr3")
FROM Table2 ds
WHERE fp.col1 = ds.col1 and fp.col2 = ds.col2 and ds.col2='ABC')) )
)
FROM Table2 fp
WHERE fp.col1 = 'XYZ'
我收到错误
ORA-00917: missing comma
00917. 00000 - "missing comma"
*Cause:
*Action:
Error at Line: 5 Column: 18
我无法理解为什么
我期待像
这样的输出<product>
<dataset></dataset>
</product>
你也可以指点教程/例子,其中xml是通过joiing多个表生成的。我需要仔细研究一下语法。
我搜索的大多数示例都是从单个表(员工)生成的xml
答案 0 :(得分:1)
--- --- EDIT
我修改了你的查询。它应该工作:
SELECT XMLElement("product"
, XMLAttributes(fp.col2 AS "attr2",fp.col4 as "attr4",fp.col5 as "attr5",fp.col6 as "attr6")
, (
SELECT XMLElement("dataset"
, XMLAttributes(ds.col3 AS "attr3")
)
FROM Table2 ds
WHERE fp.col1 = ds.col1 and fp.col2 = ds.col2 and ds.col2='ABC'
)
)
FROM Table2 fp
WHERE fp.col1 = 'XYZ';
在您的查询中有不必要的XMLElement
子句(第二个),在子查询之前缺少逗号。