Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Fetching data from Oracle Table in a shell script variable

851268Jul 4 2011 — edited Jul 5 2011
Hi All,

I need to fetch the values stored in tables residing in Oracle database into shell script variables. Below is the code snippet I am using to achieve the same
CNT=`$ORACLE_HOME/bin/sqlplus -s $CONNSTRING <<EOF
SELECT records_processed FROM table1;
exit
EOF`

echo $CNT
Answer to above select statement is 40. However, the result of above echo is RECORDS_PROCESSED -----------------40. I am not able to get rid of this extra bit (RECORDS_PROCESSED -----------------)coming everytime in echo. I have tried using cut, but the result of the select statement can vary from time to time. So cannot define a definite limit to cut exactly till which position. Please suggest a way to fetch just value 40 in the shell variable and also the reason why it displayes the table's column name along with its value.

Many Thanks.
This post has been answered by Dude! on Jul 4 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 2 2011
Added on Jul 4 2011
3 comments
6,377 views