Search code examples
shellunixinformix

Shell script for insert multiple records into a Database


I have a table in an Informix DB into which I want to insert multiple records at a time. Data for one of the column should be unique & other column data may be the same for all the records I insert

Typical Insert Statement I use to insert one row :

insert into employee(empid, country, state) values(1, us, ca)

Now I want to pass different values for the 'empid' column, & data in rest of the columns can remain the same.

I am looking for something like looping empid & prompting user to enter the Start & End range of values for empid When User enters Start Value as 1 & End Value as 100, the script should inset 100 records with empid's from 1 to 100


Solution

  • Please notice that you need to pass the start and end parameters as input arguments to your script:

    #!/bin/sh
    
    start=$1
    end=$2
    
    while [[ $start -le $end ]];
    do
      echo "insert into employee(empid, country, state) values(${start}, us, ca)"
      start=`expr $start + 1`
    done