These are my emp table records
EmpId EmpName
1 AAA
2 CCC
3 BBB
I want to generate xml in below format.
<emp>
<1>AAA</1>
<2>CCC</2>
<3>BBB</3>
</emp>
What is the required sql query?
4 3273
Are you looking at something like this: -
with t as (select 1 empid, 'AAA' name from dual
-
union all select 2, 'BBB' from dual
-
union all select 3,'CCC' from dual)
-
SELECT XMLELEMENT("EMP",XMLAGG(XMLELEMENT(empid,XMLATTRIBUTES(empid),name))) from t
-
/
-
-
<EMP><EMPID EMPID="1">AAA</EMPID><EMPID EMPID="2">BBB</EMPID><EMPID EMPID="3">CCC</EMPID></EMP>
-
-
The way you want the XML to be generated will fail in parsing because XML tag changes as per empid.
You can: -
with t as (select 1 empid,'AAA' name FROM dual
-
union all select 2, 'BBB' from dual
-
union all select 3,'CCC' from dual)
-
select col from
-
(SELECT '<EMP>' col,0 FROM dual
-
UNION
-
SELECT '<'||empid||'>'||name||'</'||empid||'>' col,rownum rn from t
-
UNION
-
SELECT '</EMP>',NULL FROM dual
-
ORDER BY 2 NULLS LAST)
-
/
-
-
<EMP>
-
<1>AAA</1>
-
<2>BBB</2>
-
<3>CCC</3>
-
</EMP>
-
-
Is the sql query not possible by using xml functions like xmlelement,xmlquery?
You can try something like this: -
with t as (select 1 empid,'AAA' ename from dual
-
union all select 2,'BBB' from dual)
-
SELECT REPLACE(col1,'ROWSET','EMP') FROM
-
(SELECT SYS_XMLAGG (XMLELEMENT(ename,XMLATTRIBUTES(empid),ename)) col1 from t)
-
/
-
-
col1
-
-----
-
-
"<?xml version="1.0"?>
-
<EMP>
-
<ENAME EMPID="1">AAA</ENAME><ENAME EMPID="2">BBB</ENAME></EMP>
-
"
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: odmoney |
last post by:
Hello,
Can anyone point me in the right direction on how one would fetch an
NCLOB datatype into c++ ?
I have read a lot of documentation on the OCI API as well as Oracle
LOBs, but cannot get...
|
by: Srinivasan R |
last post by:
Hi,
I am trying to get asynchronous fetching of data from sql server database. I
would like to show the progress of fetching records in GUI. Is there any
simple/complex steps for the same in C#...
|
by: carl.barrett |
last post by:
Hi,
I am writing to a text file the records in an access table that is to
be loaded into an Oracle system.
However, I have been told that the date fields in the records I have
exported to the...
|
by: deepdata |
last post by:
Hi,
I am trying to fetch data from db2 (express version) database by
calling stored procedure. I have tried to use both cursor and for loop
but still i am getting error.
--======Start...
|
by: Jenden0 |
last post by:
I'm new to C# (and Microsoft in general) so this may be a simple
problem, but I haven't been able to figure it out yet.
I've got a database with a number of different tables and I want the
user...
|
by: ameen.abdullah |
last post by:
Hi Guys,
I have a datagrid which is binded to dataset which is gettting data
from xml. Now i need to know if i edit or add data to the datagrid,
whats the best possible way to fetch it? .. i...
|
by: Bhavesh |
last post by:
Hello genious people,
I m trying to insert a LARGE text from Multiline Textbox into my table
of sqlserver2000. I m using vs-2005.
Please note that I dont want to store blob data From FILE TO...
|
by: Frank Moyles |
last post by:
I have two simple function in PHP that I want to convert to C# -
function Doit($enc_user_name, $enc_password)
{
$result = $mysqli->query("call
sp_userAuth('$enc_user_name','$enc_password')");
...
|
by: =?Utf-8?B?S3VydA==?= |
last post by:
I was wondering if anyone knew if there was a simple way to convert a Data
Interchange Format (.dif) file
(see:http://en.wikipedia.org/wiki/Data_Interchange_Format) into a dataset
using the native...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |