If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > script for inserting a value into the table repeatedly

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-07, 19:08
rajaryan4545 rajaryan4545 is offline
Registered User
 
Join Date: Nov 2007
Posts: 27
script for inserting a value into the table repeatedly

hi all,


i would like to insert a single value into a table repeatedly.
can any one please tell me how to write a shell script for inserting a same value into a table repeatedly.

example:

insert into test.temporary (usagedate) values ('2006-05-22');

actually there is another coloumn customerid which is a
GENERATED ALWAYS AS IDENTITY along with USAGEDATE

this value 2006-05-22 should be inserted repeatedly into the table temporary.
i think we have to use a loop in the script but i have no idea of using a loop in the shell script.

i am using db2 V9.1 fp0 on AIX

Thanks...
Reply With Quote
  #2 (permalink)  
Old 12-14-07, 01:39
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Say, if you want to insert this value 100 times, you can do

insert into t(usagedate)
with temp(a,b) as
(
values(1,current date)
union all
select a+1,current date from temp where a<100
)
select b as usagedate from temp

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 12-14-07, 04:00
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Code:
BEGIN
   DECLARE i INT DEFAULT 0;
   WHILE ( i < 100 ) DO
      INSERT INTO test.temporary (usagedate)
         VALUES ('2006-05-22');
      SET i = i + 1;
   END WHILE;
END@
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On