0

我需要像

<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 列

4

2 回答 2

3

我认为问题在于第 16 行

FROM File_Filter ff where ff.dataset_code=ds.dataset_code) ,

末尾的逗号表示 Oracle 在第 18 行的 )) 之前期待另一个表达式。

于 2013-07-18T13:20:19.090 回答
0

您的代码中的问题:

  1. 正如@stevo 所写:不必要的逗号
  2. XMLForest在第一条语句里面的部分SELECT别名错误WHERE
  3. 你不应该使用XMLForest,你应该使用XMLConcat
  4. SELECT不需要在主表中加入两个表。小修改后:change WHEREpart to WHERE ds.File_Name = 'abc' and ds.dataset_code ='123'tableFile_Product无处使用。
于 2013-07-18T15:54:41.273 回答