Shell script for insert multiple records into a Database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for insert multiple records into a Database
# 1  
Old 07-11-2013
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 :

Code:
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

Last edited by Scott; 07-12-2013 at 04:43 AM.. Reason: Code tags
# 2  
Old 07-11-2013
you should post what you have done so far so people can see where you are getting stuck ...
# 3  
Old 07-12-2013
I am new to this area and so I am seeking some help
# 4  
Old 07-12-2013
Start with this script:
Code:
#!/bin/bash
printf "empID lo: "
read empID_lo
printf "empID hi: "
read empID_hi
printf "country: "
read country
printf "state: "
read state
printf "value #1/3: "
read val1
printf "value #2/3: "
read val2
printf "value #3/3: "
read val3
ei=$empID_lo
while [ $ei -le $empID_hi ]
do
 echo "employee($ei, $country, $state) values($val1, $val2, $val3)" 
 ei=$(($ei+1))
done

# 5  
Old 07-12-2013
That didnt work
See an error with the line where there is while statement
# 6  
Old 07-12-2013
If you have large no records to insert into databse..instead of using the loop to insert the records..then use sqlldr command.

Here you can put all of your records in a csv file...the control file contains the details like where will be the csv file location.

Code:
 
sqlldr $usrname\@dbname/password control=data.ctl log=logfile bad=out.bad discard=data.discard data=data.csv silent=all

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Intelligent Script to Insert Records in Database Table

Hello All Members, I am new to this forum and to the shell scripting. I want to write a shell script to do the following: Scenario: I have a pipe delimited .txt file with multiple fields in it. The very first row of the file contains the name of the column which resembles the name of the... (18 Replies)
Discussion started by: chetanojha
18 Replies

2. Shell Programming and Scripting

Need help on Insert data to phpMyAdmin mySQL database from Shell Script

Sorry to disturb you, I would like to seek help on inserting data whenever the switch is on or off to my phpMyAdmin mySQL database from my Shell Script. I'm using Raspberry PI as my hardware and I have follow this LINK: instructables.com/id/Web-Control-of-Raspberry-Pi-GPIO/?ALLSTEPS to create my... (4 Replies)
Discussion started by: aoiregion
4 Replies

3. Shell Programming and Scripting

shell script for saving oracle database records in variable

i want to retrieve value in each column of each row in sql plus and save them into array variable and echo the value in array variable (2 Replies)
Discussion started by: ramish
2 Replies

4. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

5. Shell Programming and Scripting

Korn shell program to parse CSV text file and insert values into Oracle database

Enclosed is comma separated text file. I need to write a korn shell program that will parse the text file and insert the values into Oracle database. I need to write the korn shell program on Red Hat Enterprise Linux server. Oracle database is 10g. (15 Replies)
Discussion started by: shellguy
15 Replies

6. Shell Programming and Scripting

Parsing record into multiple records in Shell Script

Hi, I am trying to parse a very long record in a text file into multiple records by checking ADD, DELETE, or MODIFY field value in a shell script. Input # File name xyz.txt ADD|N000|8015662|DELETE|N001|9915662|MODIFY|N999|85678 Output ADD|N000|8015662| DELETE|N001|9915662|... (8 Replies)
Discussion started by: naveed
8 Replies

7. Shell Programming and Scripting

shell script to insert data from gps.txt to mysql database

Hi, I have gps receiver, by using gpsd data i can read gps log data to my database(my sql). Steps: 1. telenet localhost 2947 > gps.txt (press enter) 2. r (press enter) //then i will get the data like below in gps.txt file Trying 127.0.0.1... Connected to localhost.... (1 Reply)
Discussion started by: gudivada213
1 Replies

8. Shell Programming and Scripting

insert values into sqlplus database using shell script

hello all, I am new to shell scripting and to unix... so the following is my assignment.. here i am trying to insert a values into sqlplus database using shell script. the following is my shell script InsertDelete.sh #! /bin/sh echo "*********The MENU******** 1.Insert The Values... (2 Replies)
Discussion started by: pradeept
2 Replies

9. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

10. Shell Programming and Scripting

Shell Script: want to insert values in database when update script runs

Hi , I am new to linux and also also to shell scripting. I have one shell script which unpacks .tgz file and install software on machine. When this script runs I want to insert id,filename,description(which will be in readme file),log(which will be in log file) and name of unpacked folder... (1 Reply)
Discussion started by: ring
1 Replies
Login or Register to Ask a Question