in shell script I have one problem while inserting into oracle table .
my script
#! /usr/bin/sh
while read record
do
echo $record
X=`sqlplus -s STN/errrmddb20@MAHFDR <<eof
insert into STN.STN_ERROR_TABLE values($record);
eof`
echo $X
done < ora.txt
hi frnd
what u r teling . i couldnt understand. i have given the samething in my script . its throwing error. even if its same , i copied ur suggested solution and ran the script. still its throws same error
my script
#! /usr/bin/sh
while read record
do
echo $record
X=`sqlplus -s STN/errrmddb20@MAHFDR <<eof
insert into STN.STN_ERROR_TABLE values($record);
eof
`
echo $X
done < ora.txt
or
my script
#! /usr/bin/sh
while read record
do
echo $record
X=`sqlplus -s STN/errrmddb20@MAHFDR <<-eof
<tab>insert into STN.STN_ERROR_TABLE values($record);
<tab>eof
`
echo $X
done < ora.txt
you have given 2 option. the 1st option and my code both are 100% same frnd. even i copied the ur code and ran the script . but its not working . :(
throws same error
yes frnd,
the value from ora.txt and the insert command fine only. thats how the value should get populated. but its not getting inserted. i dont know why :(
Is that the form of INSERT statement that you want to execute ?
Does it run successfully from the "SQL>" prompt of sqlplus ?
Note that the string delimiter in Oracle is the single-quote character, and in its absence, Oracle assumes the data to consist of identifiers instead of strings.
The "eof" error comes from sqlplus (not the Oracle server), because sqlplus does not understand "eof".
In a production environment I suggest NOT to use this approach for following reasons:
a) you connect to the database for every single record in your file.
b) your code may fail depending on your input file. Especially single quotes as data will give you trouble.
c) you kill your DB-performance by flooding it's SGA with your statements. Ask your DBA about the advantage of bind-variables.
I recommend to use SQL*Loader for this task. Depending on your DB-Version a construct inside the DB called "External Tables" may also be used to solve your problem.