Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XMLElement function not working as expected

Posted on 2007-11-21
4
Medium Priority
?
639 Views
Last Modified: 2011-09-20
I have a table called players with the following attributes and values:

 PLAYER_ID PLAYER_NAME
---------- ------------
         1 Smith
         2 Jones
         3 Wilson

When I issued this query,
select XMLElement("Player",
          XMLElement("PlayerID",player_id),
          XMLElement("PlayerName",player_name))
from players;

I expected to see results something like this

<Player>
  <PlayerID>1</PlayerID>
  <PlayerName>Smith</PlayerName>
</Player>
<Player>
  <PlayerID>2</PlayerID>
  <PlayerName>Jones</PlayerName>
</Player>
<Player>
  <PlayerID>3</PlayerID>
  <PlayerName>Wilson</PlayerName>
</Player>

but what actually returned was

XMLTYPE()
XMLTYPE()
XMLTYPE()

Is there something I need to do to get this to work?
0
Comment
Question by:awking00
  • 4
4 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 20330544
xmlelement returns xmltype's

each type contains the player node you're looking for

0
 
LVL 74

Expert Comment

by:sdstuber
ID: 20330561
btw, off topic, please post your code about the iso weeks, I never did figure out what you were doing with the function based index that pertained to that question.
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 20330650
uset the getclobval() method of the returned xmltype's to see the contents

select XMLElement("Player",
          XMLElement("PlayerID",player_id),
          XMLElement("PlayerName",player_name)).getclobval()
from players;
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 20330661
And if you wanted all of the rows to be inside a single xml doc,
then use xmlagg to aggregate them.

and, that too returns an xmltype, so use getclobval on the xmlagg's returned value to see the combined xml


select XMLAGG(XMLElement("Player",
          XMLElement("PlayerID",player_id),
          XMLElement("PlayerName",player_name))
       ).getclobval()
from players;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question