我需要像
<dataset code="123" title="" pubcode="456" minrows="0">
<schema code="s1" /> <!-- can be one -->
<rowset code="rs1" /> <!-- can be one -->
<sorter>
<!-- field can be MORE than one -->
<field name="field1" order="o1"/>
<field name="field2" order="o2"/>
</sorter>
<!-- filter can be MORE than one -->
<filter type="filter1" value="val1" />
<filter type="filter2" value="val2" />
</dataset>
其中每个标签对应一个单独的表。并且该标记中的每个属性都是相应表中的一列在sql下面写了相同的
SELECT XMLELEMENT(NAME "dataset",
XMLAttributes(ds.DataSet_Code AS "code",ds.DataSet_Title as "title",ds.pub_code as "pubcode",ds.Min_Rows as "minrowss"),
XMLFOREST(
(SELECT XMLElement("schema", XMLAttributes(fs.schema_code AS "code"))
FROM File_Schema fs WHERE fr.dataset_code = ds.dataset_code),
(SELECT XMLElement("rowset", XMLAttributes(fr.rowset_code AS "code")) FROM File_RowSet fr
WHERE fr.dataset_code = ds.dataset_code),
(SELECT XMLELEMENT(NAME "sorter",
XMLAGG(XMLELEMENT(NAME "field",
XMLATTRIBUTES(fsf.field_name AS "name",fsf.field_order AS "order")
)
)
)
FROM File_sorter_field fsf WHERE fsf.dataset_code=ds.dataset_code),
(SELECT XMLAGG(XMLELEMENT(NAME "filter", XMLATTRIBUTES(type AS "type",value AS "value")))
FROM File_Filter ff where ff.dataset_code=ds.dataset_code)
))
FROM File_Product fp , File_DataSet ds
WHERE fp.File_Name = ds.File_Name and fp.File_Name = 'abc' and ds.dataset_code ='123' ;
我得到如下错误
ORA-19208: parameter 1 of function XMLFOREST must be aliased 19208. 00000
- "parameter %s of function %s must be aliased" *Cause: The indicated parameter
of the XML generation function has not been aliased, although it is an expression.
*Action: Specify an alias for the expression using the AS clause.
Error at Line: 19 Column: 5
任何帮助表示赞赏
根据 KPater87 修改查询
SELECT XMLELEMENT(NAME "dataset",
XMLAttributes(ds.DataSet_Code AS "code",ds.DataSet_Title as "title",ds.pub_code as "pubcode",ds.Min_Rows as "minrowss"),
XMLConcat(
SELECT XMLElement("schema", XMLAttributes(fs.schema_code AS "code"))
FROM File_Schema fs WHERE fs.dataset_code = ds.dataset_code,
SELECT XMLElement("rowset", XMLAttributes(fr.rowset_code AS "code")) FROM File_RowSet fr
WHERE fr.dataset_code = ds.dataset_code,
SELECT XMLELEMENT(NAME "sorter",
XMLAGG(XMLELEMENT(NAME "field",
XMLATTRIBUTES(fsf.field_name AS "name",fsf.field_order AS "order")
)
)
)
FROM File_sorter_field fsf WHERE fsf.dataset_code=ds.dataset_code,
SELECT XMLAGG(XMLELEMENT(NAME "filter", XMLATTRIBUTES(type AS "type",value AS "value")))
FROM File_Filter ff where ff.dataset_code=ds.dataset_code
))
FROM File_DataSet ds
WHERE ds.File_Name = 'abc' and ds.dataset_code ='123' ;
仍然得到错误
ORA-00936:缺少表达式 00936。00000 -“缺少表达式” *原因:
*操作:第 4 行错误:第 28 列