次のようなxmlを取得する必要があります
<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でエラーが発生しました