The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
(sed) parsing insert statement column that crosses multiple lines jjordan Shell Programming and Scripting 3 10-08-2007 09:23 PM
Need to execute the same statement Legend986 Shell Programming and Scripting 8 10-01-2007 01:59 PM
How do i execute in IF ELSE Statement laknar Shell Programming and Scripting 1 06-07-2007 11:54 PM
Insert TAB in echo statement sunils27 Shell Programming and Scripting 5 08-26-2005 12:36 AM
awk command for INSERT statement nattynatty Shell Programming and Scripting 4 05-10-2002 11:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-24-2006
Registered User
 

Join Date: Aug 2006
Posts: 54
Script does not execute Insert Statement

Hi

I have a text file , contents are
Line1:field1,field2,field3,field4,field5,field6.......field20
Line2:field1,field2,field3,field4,field5,field6.......field20
Line3:field1,field2,field3,field4,field5,field6.......field20
....and so on...

I want to read this file and insert the data into table.

How can I do that...can anybody help ?
I tried to read the text file , each line, cut the fields, make connection to database and then execute the Insert Statement....
But when I do this the Insert statement does not execute.
Can anybody guide me how do I achieve this ?

Code:
#####Connecting sqlplus to check the connectivity
sqlplus -s /nolog <<EOF>/dev/null
connect ${DB_LOGIN}/${DB_PASSWORD}@${DB_NAME}

cat /$FILEPATH/$FILENAME | while read LINE
do
    echo ${LINE}
    acctno=`echo $LINE | cut -f1 -d','`
    echo $acctno
    salutation=`echo $LINE | cut -f2 -d','`
    name=`echo $LINE | cut -f3 -d','`
    billdate=`echo $LINE | cut -f4 -d','`
    totaldue=`echo $LINE | cut -f5 -d','`
    billdeductiondate=`echo $LINE | cut -f6 -d','`
    billduedate=`echo $LINE | cut -f7 -d','`
    templatecode=`echo $LINE | cut -f8 -d','`
    billid=`echo $LINE | cut -f9 -d','`
    emailid=`echo $LINE | cut -f10 -d','`
    brnno=`echo $LINE | cut -f11 -d','`
    billsummaryid=`echo $LINE | cut -f12 -d','`
    batchno=`echo $LINE | cut -f13 -d','`
    emailfile=`echo $LINE | cut -f16 -d','`
    echo "Insert into table"

    spool ${SYS_TEMP_DIR}/${JOB_ID}_db_sql.log
    INSERT INTO SendMailDetails (acctno) values ('${acctno}');
    echo "Table Appended"
    commit;
    spool off;
    exit;
    EOF
done
I also tried:

Code:
MYCOMMAND=`awk '$1' ${FILEPATH}${FILENAME}`
sqlplus -s /nolog <<EOF>/dev/null
connect ${DB_LOGIN}/${DB_PASSWORD}@${DB_NAME}

spool my.log
Insert into SendMailDetails(acctno) values($MYCOMMAND);
spool off
commit;
exit
EOF;
But am unsuccessfull, Please help.....
Reply With Quote
Forum Sponsor
  #2  
Old 08-24-2006
Registered User
 

Join Date: Jul 2006
Posts: 19
I think its pretty easy to use sql loader for your purpose.
Reply With Quote
  #3  
Old 08-24-2006
Registered User
 

Join Date: Aug 2006
Posts: 54
Thanks Mukund

Atleast I got a direction...

Thanks
Amruta
Reply With Quote
  #4  
Old 08-24-2006
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
Amruta, you could use the shell to do this quite easily:
Code:
#####Connecting sqlplus to check the connectivity
sqlplus -s /nolog <<EOF>/dev/null
connect ${DB_LOGIN}/${DB_PASSWORD}@${DB_NAME}
oldIFS=$IFS
IFS=,
while read acctno salutation name billdate totaldue billdeductiondate billduedate templatecode billid emailid brnno billsummaryid batchno field14 field15 emailfile rest_of_the_fields; do
    echo "Insert into table"
# insert into whatever table, whichever values that you want
# after you are done, go ahead
    echo "Table Appended"
    commit;
    spool off;
    exit;
    EOF
done
field14, field15: hold the 14th and 15th fields, rest_of_the_fields: holds the fields from 17 to end of line. Everything else goes into the appropriately named variables.
Reply With Quote
  #5  
Old 08-24-2006
Registered User
 

Join Date: Aug 2006
Posts: 54
Thumbs up SQL Loader to Append Data

Hi there
I worked on Mukund's suggestion to use sqlloader...it worked successfully.
this is the main shellscript
LoadMain.sh

Code:
#!/usr/bin/ksh

DB_LOGIN=SOMESYSTEM
DB_PASSWORD=SOMEPASSWD
DB_NAME=SOMENAME
FILENAME="$1"

sqlldr ${DB_LOGIN}/${DB_PASSWORD}@${DB_NAME} control=tryloader log=mlist2.log data=mlist2.txt

echo "I am done"
-------------
data=mlist.txt is the Input text file which contains data with delimiters.
control=tryloader.ctl is the Control file which contains information as to how the data will be appended to the table...
My tryloader.ctl contains :
Code:
LOAD DATA
APPEND INTO TABLE SendMailDetails
(
  AcctNo CHAR TERMINATED BY ",",
  Salutation CHAR TERMINATED BY ",",
  Name CHAR TERMINATED BY ",",
  BillDate CHAR TERMINATED BY ",",
  TotalDue DECIMAL EXTERNAL TERMINATED BY ",",

 ...and other fields
)
And again..thanks Guys....

Amruta Pitkar
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0