473,394 Members | 1,750 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,394 software developers and data experts.

insert same row multiple times

As a converted sybase dba, I have a question. In sybase a command can
be executed multiple times by placing a

go 1000

at the end of the statement. Such as:

insert into a (col1, col2)
values (1,2)
go 1000

this will put the values 1 and 2 in the respective columns for 1000
rows.

Is there an equivalent in db2 udb, v8.2.2?

Thank you,

Kermit Lowry

Feb 20 '07 #1
3 7948
Ultrak The DBA wrote:
As a converted sybase dba, I have a question. In sybase a command can
be executed multiple times by placing a

go 1000

at the end of the statement. Such as:

insert into a (col1, col2)
values (1,2)
go 1000

this will put the values 1 and 2 in the respective columns for 1000
rows.

Is there an equivalent in db2 udb, v8.2.2?
Not through the driver, but you can write this many different ways:
--#SET TERMINATOR @
BEGIN ATOMIC
DECLARE i INT DEFAULT 0;
WHILE i < 100 DO
INSERT INTO T VALUES (1, 2);
END WHILE;
END
@
--#SET TERMINATOR ;

Or you can use recursion:
INSERT INTO T WITH rec(c1, c2, i) AS
(VALUES (1, 2, 0)
UNION ALL
SELECT c1, c2, i + 1 FROM rec WHERE i < 100)
SELECT c1, c2 FROM rec;

Or use the fact that DB2 supports multi row insert:
INSERT INTO T VALUES
(1, 2), .... (1, 2);
or use your shell

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 20 '07 #2
Serge Rielau wrote:
Or you can use recursion:
INSERT INTO T WITH rec(c1, c2, i) AS
(VALUES (1, 2, 0)
UNION ALL
SELECT c1, c2, i + 1 FROM rec WHERE i < 100)
SELECT c1, c2 FROM rec;
Interesting. If you needed to use a CTE (with or without recursion)
for a DELETE or UPDATE statement, what would that look like? Or is it
even possible?

Feb 20 '07 #3
INSERT INTO T
SELECT 1, 2
FROM (VALUES 0,1,2,3,4,5,6,7,8,9) p1(n)
,(VALUES 0,1,2,3,4,5,6,7,8,9) p2(n)
,(VALUES 0,1,2,3,4,5,6,7,8,9) p3(n)

Feb 21 '07 #4

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,...
8
by: pb648174 | last post by:
I have a single update statement that updates the same column multiple times in the same update statement. Basically i have a column that looks like .1.2.3.4. which are id references that need to...
3
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
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
7
by: Nathan Sokalski | last post by:
I have user controls that contain a link to a stylesheet. Several of my pages also have a link to this same stylesheet. Because of this, the resulting output contains multiple links to the same...
5
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
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...
1
by: omaragainonthetrack | last post by:
public void InsertPlannedMaterialMasterRequest(int id, string requestDocument, string requestDescription, string requestType, string hodApproval, int companyCode, string hodRemarks, string...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
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...

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.