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? :confused:

Is this SQL Loader you are using to load data into oracle database?

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.

Something on the lines of :

#!/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

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.