Sql query through shell script

hey , i am using this code to store value of a sql query and and then use
it in other query but after some time , but it is not working. please help

#!/bin/bash
val_1=$( sqlplus -s rte/rted2@rel76d2 << EOF
setting heading off
select max(stat_id) from cvt_stats;
exit
EOF
)
nohup ./cvt -f MediationSources.xml &
sleep 60
val_2=$( sqlplus -s rte/rted2@rel76d2 << EOF
setting heading off
select source_id from cvt_istats where istat_id > val_1;
exit
EOF
)

$ sign missing in variable val_1

hey , i used this then
but the value is not being inserted in the table

#!/bin/bash
val_1=$( sqlplus -s rte/rted1@rel75d1 << EOF
setting heading off
select max(stat_id) from cvt_stats;
insert into mukti(stat_id) values( $val_1 );
exit
EOF
)
echo  "val_1: $val_1"
nohup ./cvt -f MediationSources.xml &
sleep 60
val_2=$( sqlplus -s rte/rted1@rel75d1 << EOF
setting heading off
select source_id from cvt_istats where istat_id > (select stat_id from mukti);
exit
EOF
)
echo  "val_2: $val_2"



You cant use val_1 before it gets populated thats why its not working..

I requested you before to debug your script first to understand what is causing any undesired behavior.

No offense, but these are silly mistakes and they can be easily uncovered by debugging your script.

I highly recommend to put some efforts yourself before posting such questions on this forum.

i am extremely sorry for this but actually i am a novice in shell scripting.
so, even if i debug it , it is not clear.

i will try to put all my efforts , then only ask on the forum.

Thanks