Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007
    Posts
    27

    Unanswered: 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...

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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.

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •