473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Insert multiple rows via XML?

I know that Oracle has extensive support for XML, but I can't seem to find
any documentation on using an XML document to do multiple inserts into a
relational table. Note, I'm *not* trying to insert an XML document into an
XmlType column. I just want to construct an XML document containing the
values for many rows, and then use this document to insert all of the rows
with a single INSERT command. I want to do this for performance, because
doing many individual INSERTs in a loop in a stored procedure yields
unacceptable performance.

If anyone can help, I'd be very grateful.

Brian
Jul 19 '05 #1
1 11102
Pipelined function can be used to insert the data in one go. This is
one example from Oracle's site

DROP TABLE T;

CREATE TABLE T (
poname varchar2(20),
postreet varchar2(20),
pocity varchar2(20),
postate char(2),
pozip char(10)
);

DROP function poExplode_func;
DROP TYPE poRow_list;
DROP TYPE poRow_type;
create type poRow_type as object
(
poname varchar2(20),
postreet varchar2(20),
pocity varchar2(20),
postate char(2),
pozip char(10)
);
/

create type poRow_list as TABLE of poRow_type;
/

create function poExplode_func (arg IN sys.XMLType) return poRow_list
pipelined is
out_rec poRow_type;
poxml sys.XMLType;
i binary_integer := 1;
argnew sys.XMLType := arg;
begin
out_rec := poRow_Type(NULL,NULL,NULL,NULL,NULL);
loop
-- extract the i'th purchase order!
poxml := argnew.extract('//PO['||i||']');
exit when poxml is null;
-- extract the required attributes..!!!
out_rec.poname := poxml.extract('/PO/PONAME/text()').getStringVal();
--out_rec.poname := argnew.extract('/POLIST/PO['||i||']/PONAME/text()').getStringVal();
out_rec.postreet := poxml.extract('PO/POADDR/STREET/text()').getStringVal();
out_rec.pocity := poxml.extract('//POADDR/CITY/text()').getStringVal();
out_rec.postate := poxml.extract('//POADDR/STATE/text()').getStringVal();
out_rec.pozip := poxml.extract('//POADDR/ZIP/text()').getStringVal();
PIPE ROW(out_rec);
i := i + 1;
end loop;
return;
end;
/

declare
s1 clob;
begin
s1 := '<PO>
<PONAME>Po_1</PONAME>
<POADDR>
<STREET>100 Main Street</STREET>
<CITY>Sunnyvale</CITY>
<STATE>CA</STATE>
<ZIP>94086</ZIP>
</POADDR>
</PO>';
s1 := s1||s1||s1||s1||s1||s1||s1||s1||s1||s1;
s1 := s1||s1||s1||s1||s1||s1||s1||s1||s1||s1;
--s1 := s1||s1||s1||s1||s1;
INSERT INTO T
select *
from TABLE( CAST(
poExplode_func(
sys.XMLType.createXML(
'<?xml version="1.0"?>
<POLIST>'||s1||'</POLIST>')
) AS poRow_list));
end;
/

select * from T;
Pratap
Cognizant Technology Solutions, India
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: RotterdamStudents | last post by:
Hello there, i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d',...
8
by: Sans Spam | last post by:
Greetings! I have a table that contains all of the function permissions within a given application. These functions are different sections of a site and each has its own permissions (READ, WRITE,...
1
by: Tuhin Kumar | last post by:
Hi, I would like to know how to insert multiple rows into a table, using a single INSERT statement. My requirement is like this I have a table ABC which contains multiple employees entries with...
4
by: fip | last post by:
Hi, On DB2 7.1.2 on MVS OS 390, when I tried to do an insert with multiple row contents in the values clause: insert into table11 values('aaaa', 'fa'), ('bbbb', 'fb') I got the error: ...
5
by: SSP | last post by:
Dear ASP.NETers, How would I insert multiple rows of data from a web form? Are there any tute's and stuff around. Couldn't find any myself. Thanks in advance. SSP
20
by: Mark Harrison | last post by:
So I have some data that I want to put into a table. If the row already exists (as defined by the primary key), I would like to update the row. Otherwise, I would like to insert the row. I've...
2
by: wombat53 | last post by:
Hi Group Are there any DB2 UDB ESE DPF V8.2 users exploiting "buffered inserts" (BIND parm INSERT BUF) *and* "multi-row INSERTS" (many rows associated with the VALUES clause of the INSERT to...
4
by: Michel Esber | last post by:
Hello, Environment: db2 V8 FP 13 LUW Our application currently uses: insert into table values ('A'),('B'),...('Z') We have used CLI arrays inserts (1000 array and commit size) and...
20
by: talktozee | last post by:
Hey, everyone! Basically, I need to insert *multiple rows* into table A from table B based upon some criteria, and I need to insert some static values along with each row from table A. For...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.