Shell Script to Load data into the database using a .csv file and .ctl file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script to Load data into the database using a .csv file and .ctl file
# 1  
Old 05-05-2006
Bug Shell Script to Load data into the database using a .csv file and .ctl file

Since i'm new to scripting i'm findind it difficult to code a script. The script has to be an executable with 2 paramters passed to it.The Parameters are
1. The Control file name(.ctl file)
2. The Data file name(.csv file)

Does anybody have an idea about it? Smilie
# 2  
Old 05-05-2006
Is this SQL Loader you are using to load data into oracle database?
# 3  
Old 05-05-2006
Yes I'm using SQL loader.I'm going to execute the shell script in the UNIX environment.I want to pass the control filename and the data filename as parameters while execution.
# 4  
Old 05-24-2006
Something on the lines of :

Code:
#!/bin/bash
if [ $# = 2 ]
then
    if [ $1 = " " -o $2 = " " ]
    then
        echo "Wrong or No arguments"
    else
        SOURCE_DIR=$HOME/Logdump
	LOG_DIR=$HOME/admin/log
	LOG_FILE=LoadSQL.log
        DATAFILE=$1
        TABLENAME=$2
        DST_FILE=$HOME/dump.ctl
        echo LOAD DATA > $DST_FILE
        echo INFILE "'"$SOURCE_DIR"/"$DATAFILE"'" >> $DST_FILE
        echo APPEND INTO TABLE $TABLENAME >> $DST_FILE
        echo FIELDS TERMINATED BY "','" OPTIONALLY ENCLOSED BY "'\"'" >>$DST_FILE
        echo TRAILING NULLCOLS >>$DST_FILE
        echo "(" >>$DST_FILE
        echo datestamp date '"Mon DD RRRR  HH:MIAM"',>>$DST_FILE
        echo request_file, >>$DST_FILE
        echo product_no, >>$DST_FILE
        echo card_no, >>$DST_FILE
        echo key_no, >>$DST_FILE
        echo message char"("1000")", >>$DST_FILE
        echo id sequence"("max,1")" >>$DST_FILE
        echo ")" >>$DST_FILE
        $HOME/admin/bin/.runme
        \rm dump.ctl
	echo "*****************************************************************" >> $LOG_DIR/$LOG_FILE 
	date '+DATE: %m/%d/%y TIME:%H:%M:%S' >> $LOG_DIR/$LOG_FILE
	echo $1 "Sucessfully Loaded into Database" >> $LOG_DIR/$LOG_FILE 
	echo "*****************************************************************" >> $LOG_DIR/$LOG_FILE 
    fi
else
    clear
    echo "*************************************************************"
    echo "*****       	<Your Comments/Company name>                          *******"
    echo "*****                             Load SQL              	                    *******"
    echo "*****         Version 1.00- 14-Jun-2004                                           *******"
    echo "*************************************************************"

    echo "Usage: LoadSQL <data file name> <table name> "
fi


and the .runme file contains


Code:
sqlldr control=$HOME/dump.ctl userid=scott/tiger errors=9999999

But the contents of the dump.ctl will be decided by the tables you have in Oracle.

enc.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Spooling data from the database in .csv file with boundary

Hi Guys, Another questions to the genius over here. I have spool the dataf from the database into a .csv file. But can it be possible to have all the rows and column with the boundaries..for example the .csv file which i have is as below: 20140327 BU 9A 3 20140327 SPACE 9A 3 20140327... (8 Replies)
Discussion started by: Pramod_009
8 Replies

2. Shell Programming and Scripting

Shell script to extract data from csv file

Hi everyone, I have a csv file which has data with different heading and column names as below. Static Data Ingested ,,,,,,,,,,,,Known Explained Rejections Column_1,column_2,Column_3,Column_4,,Column_6,Column_7,,% Column_8,,Column_9 ,Column_10 ,... (14 Replies)
Discussion started by: Vivekit82
14 Replies

3. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 7 columns having values say column 1,column 2.....column 7 as below along with their values. Name, Address,... (7 Replies)
Discussion started by: Vivekit82
7 Replies

4. Shell Programming and Scripting

why do we need UNIX shell script to load data into Oracle database

Hello everyone, I am new to shell scripting/ loading data into a database. I want to load data into Oracle database using SQL loader. Can some one please explain why do we need unix shell script to load the data into the database? Also can someone please explain what has to be in that script?... (5 Replies)
Discussion started by: new_prog
5 Replies

5. Shell Programming and Scripting

Shell script to find specific file name and load data

I need help as to how to write a script in Unix for the following: We have 3 servers; The mainframe will FTP them to a folder. In that folder we will need the script to look and see if the specific file name is there and load it to the correct table. Can anyone pls help me out with... (2 Replies)
Discussion started by: msrahman
2 Replies

6. Web Development

script to load data from csv file

hello i want a script to load the data line by line from a csv file into a mysql table (3 Replies)
Discussion started by: srpa01red
3 Replies

7. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

8. Shell Programming and Scripting

Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it. Requirement: files are ftp to... (1 Reply)
Discussion started by: dba_nh
1 Replies

9. Shell Programming and Scripting

Need Shell Script to upload data from Text file to Oracle database

Hi Does any one have any idea on uploading the data using Unix Shell script from text file to Oracle database. Requirement:- 1. Need to connect to Oracle database from Unix Shell script. 2. Need to pick Text file from some location on Unix Box. 3. Need to upload the data from text file to... (6 Replies)
Discussion started by: chandrashekharj
6 Replies

10. Shell Programming and Scripting

unix script to export data from csv file to oracle database

Hello people, Need favour. The problem I have is that, I need to develop a unix shell script that performs recurring exports of data from a csv file to an oracle database. Basically, the csv file contains just the first name and last name will be dumped to an Unix server. The data from these... (3 Replies)
Discussion started by: vinayagan
3 Replies
Login or Register to Ask a Question