0

当我跑步时

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 的教程/示例。我需要仔细看看语法。

我搜索的大多数示例都是从单个表(员工)生成的 xml

4

1 回答 1

1

- -编辑 - -

我已经修改了你的查询。它应该工作:

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子句(第二个),并且在子查询之前缺少逗号。

于 2013-07-18T07:11:56.060 回答