XML 'IN' list [message #332972] |
Thu, 10 July 2008 03:56 |
srraajesh
Messages: 63 Registered: May 2005
|
Member |
|
|
Hi Gurus,
I'm trying to push XML data into a table and read it as a 'IN' list in a SQL. This is what I've done so far.
SQL> select * from v$version
2 /
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
PL/SQL Release 9.2.0.5.0 - Production
CORE 9.2.0.6.0 Production
TNS for Solaris: Version 9.2.0.5.0 - Production
NLSRTL Version 9.2.0.5.0 - Production
SQL> create table test
2 (
3 tst_fld XMLTYPE
4 )
5 /
Table created.
SQL> insert into test
2 select XMLELEMENT("TABLES",xmlagg(XMLELEMENT("TABLENAME",TABLE_NAME))) from
all_tables where rownum < 5
3 /
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test
2 /
TST_FLD
--------------------------------------------------------------------------------
<TABLES><TABLENAME>TAB$</TABLENAME><TABLENAME>USER$</TABLENAME><TABLENAME>BOOTSTRAP$</TABLENAME><TAB
LENAME>UNDO$</TABLENAME></TABLES>
Now, If I give
select extract(tst_fld,'TABLES/TABLENAME') from test
I can get the 'TABLENAME' as a set of nodes. Is it possible to give the values directly as a list to a SQL query. Something like
select * from tablea where fld1 in (<XML node values related to 'TABLENAME'>)
I hope I've made it clear. Please let me know otherwise.
[Updated on: Thu, 10 July 2008 04:04] by Moderator Report message to a moderator
|
|
|
|
|
|
Re: XML 'IN' list [message #333060 is a reply to message #332977] |
Thu, 10 July 2008 07:03 |
rajatratewal
Messages: 507 Registered: March 2008 Location: INDIA
|
Senior Member |
|
|
srraajesh wrote on Thu, 10 July 2008 03:56
select * from
tablea
where
fld1 in
(<XML node values related to 'TABLENAME'>)
fld1 is of xmltype or something else.
Regards,
Rajat
|
|
|
|
|
Re: XML 'IN' list [message #333352 is a reply to message #333065] |
Fri, 11 July 2008 06:22 |
srraajesh
Messages: 63 Registered: May 2005
|
Member |
|
|
Michel,
One more slight twist..Suppose that I have the data like this
<root>
<b1>1,2,3,4,5</b1>
<b2>2,3,4,5,6</b2>
</root>
How can we rephrase the SQL to pick all the values of the tag b1 in a 'in' list? We can write a PL / SQL for this, but is this possible with a SQL itself directly?
|
|
|
|
Re: XML 'IN' list [message #333381 is a reply to message #333351] |
Fri, 11 July 2008 07:52 |
|
Michel Cadot
Messages: 68716 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
srraajesh wrote on Fri, 11 July 2008 13:17 | fld1 is a normal DB field. It is not of XML type.
Regards
|
Query returns strings not xmltype.
Regards
Michel
|
|
|