Insert value to db from text file

Hi,

I have a single value in insertval file. I want to load that value to database with the current date. I tried the below code but it is inserting <NULL> to database and echo $c is also null.

cat insertval | awk -F ' ' '{print $1}'  > c
echo c=$c
data=`sqlplus -s user/pwd@hostname <<EOF 
insert into Table_Name (curr_date, value) VALUES (sysdate, '$c');
commit;`
exit;
SQL
done

Regards
Neethu

You are redirecting to a FILE and reading from a VARIABLE?
Those are 2 different things.

Hi,

I want to read the value from insertval file.

cat insertval
1.1

I want to load this 1.1 with the current date to the db.

Regards
Neethu

Replace your first line with c=$(<insertval) and let me know.

1 Like

And, the HERE document is not terminated with an EOF, and, the SQL command is terminated prematurely (between commit and exit) by a backtick.

1 Like

Thanks elixir and Rudic for the immediate response...

Thanks Elixir... Now the script is working fine and inserting value to DB.

Once again thanks a lot..:slight_smile: