How to make this Xquery request in XMLQuery

Hello world
If I have these tables
create books (books, varchar2 (64), XML_DOCUMENT XMLType);
Create table review (FILENAME, varchar2 (64), XML_DOCUMENT XMLType);

and populated by
INSERT INTO (books, XML_DOCUMENT) VALUES ('books', xmltype ('))
< library >
< Book category = "COOKING" >
< title lang = "fr" > < /title > Italian newspaper
< author > Giada De Laurentiis < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
< / book >
< Book category = "COOKING" >
< title lang = "fr" > < /title > Italian newspaper
< author > Norah < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
< / book >
< Book category = "COOKING" >
< title lang = "fr" > < /title > Italian newspaper
Rama < author > < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
< / book >
< Book category = "COOKING" >
< title lang = "fr" > < /title > Italian newspaper
< author > love < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
< / book >
< Book category = "COOKING" >
< title lang = "fr" > < /title > Italian newspaper
< author > Dedo < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
((< / book > '));

INSERT INTO test (FILENAME, XML_DOCUMENT) VALUES ('Journal', xmltype ('))
< test >
Italian newspapers < title > < /title >
< author > Giada De Laurentiis < / author >
< year > 2005 < / year >
< price > 30.00 < / price >
< / review >
') );

and I want this xquery in XMLTYPE level
for $a in doc ("F:\movie\books.xml") / / title,.
$b in //review doc ("F:\movie\review.xml")
where $a = $b / title
return < result > {$a, $b/author} < / result >

Just answer me quickly I have a problem with this

Hi Nina,

can you please explain a bit what you expect the output of your XQuery?
Do you want the library books for which there is a review, or just books where the title is the same with a book that was reviewed?

The two cases above do not produce the same result...

To answer your question, in order to execute the request of Michael in your environment, all you have to do is drop the subquery clauses weighted (i.e. everything that precedes him ' select * from xmltable "part) and also to replace the column names and the table in the clause of passage with what is appropriate.
In your case, "xmltype (cursor (select * books))" should be replaced by "xmltype (cursor (select XML_DOCUMENT from books))" and "xmltype (cursor (select * review)) should be replaced by" xmltype (cursor (select review XML_DOCUMENT)) ".»

If you want the books to the library for which a review is, then you need to replace your query with
{code}
Select * from xmltable (' for $i in $rv / / review)
for $j in $bk / / book [title = $i / title and author = $i / author]
return the result of the element {$j/title/text (), ', ', $j/author/text ()}
"passing xmltype (cursor (select * from books)) as"bk ",
XmlType (cursor (select * from revision)) as "rv")
{code}

Best regards

Philippe

Tags: Database

Similar Questions

Maybe you are looking for