2016-06-14 13 views
-1

を得る:は、SQLを介してXML文書を作成するが、私は、XML文書を作るために小さなクエリを持っている構文エラー

Select XMLELEMENT(NAME movie, 
XMLFOREST(Movie.name as title, year as year, rating as rating, plot_outline as plot, 
XMLELEMENT(NAME actor, 'actor', 
XMLAGG(
XMLELEMENT(NAME role, Acts.role) 
), 
XMLAGG(
XMLELEMENT(NAME person, Person.name)) 
))) 
as result from Movie, Acts, Person 
where Movie.mid = Acts.mid 
and Acts.pid = Person.pid 

しかし、私はこのエラーを取得する:

ERROR: unnamed XML element value must be a column reference 
LINE 3: XMLELEMENT(NAME actor, 'actor', 
     ^

これをすることになっていました私の予想されるXML結果:

<movie> 
<title>Godfather, The</title> 
<year>1972</year> 
<rating>9.0</rating> 
<plot>A Mafia boss' son, previously uninvolved in the business, takes over when his father is critically wounded in a mob hit.</plot> 
<actor> 
<role>Don Vito Corleone</role> 
<person>Robert De Niro</person> 
</actor> 
<actor> 
<role>Someone else</role> 
<person>Someone else</person> 
</actor> 

</movie> 

このエラーメッセージを取り除くにはどうすればよいですか?

答えて

0

1)xmlelementで "name"という単語を省略することができます。 xmlelment(name "name" ...)= xmlelment( "name" ...)。

2)無名XML要素の値は列参照でなければなりません。そのエラーはxmlforest関数によって発生します。

xmlforest(col1, col2 as "TEST") - works fine

xmlforest(col1,xmlelement("TEST")) - throws error should be xmlforest(col1,xmlelement("TEST") as "xxx")

3)XMLELEMENT(NAME actor, 'actor'あなたはドンはこれを必要とします。あなたの質問が分かりましたら2つのxmlaggを1つのxmlelementに連結しようとします。これを行うにはxmlconcat(xmlagg(..),xmlagg(..))

4)Finallクエリ。

select xmlelement(
      movie 
      , xmlforest(Movie.name as title 
        , year as year 
        , rating as rating 
        , plot_outline as plot 
        , xmlconcat(xmlagg(xmlelement(role, Acts.role)), xmlagg(xmlelement(person, Person.name))) as "actor")) 
      as result 
     from Movie, Acts, Person 
    where Movie.mid = Acts.mid and Acts.pid = Person.pid 

適切なgroup by句を追加する必要もあります。別の例外が発生するためです。 ORA-00937:単一グループ・グループ機能ではありません

関連する問題