Writing sqlplus output to shell script variable

I want to execute a sql statement using sqlplus inside a KSH script. I want to execute a simple count(*) on a number of tables and send the results out to variables in my script. The following code worked with our old Alpha servers but doesn't now that we've switched to HP-UX's. Can someone tell me what I nee to change to get this script to work?
 
 As shown in the code snippet example, I want to send to number of rows in each table to the variables var1 and var2 where I can do comparisons and print out the values.
Thanks.

var1=`sqlplus ${C21_CONNECT} <<-        endsql
                select count(*) from CES_CUSTOMERS
                exit
        endsql`
 
        var2=`sqlplus ${RDBMS_CONNECT} <<-      endsql1
                        select count(*) from CES_CUSTOMERS
                        exit
                endsql1`

Open in new window

GeekManAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GeekManAuthor Commented:
BTW...I'm willing to abandon my old method if there's a better way....
0
TintinCommented:
When using here docs, it's always easier to use them without whitespace, eg:


var1=`sqlplus ${C21_CONNECT} <<endsql
                select count(*) from CES_CUSTOMERS
                exit
endsql`

Open in new window

0
GeekManAuthor Commented:
I suppose I should add that the script appears to run but the variables get assigned what looks like all this Oracle chatter. See attached results when I run the script....and maybe this is more a sqlplus thing. I need to supress all the Oracle connectvity and execution chatter and somehow cut through to the results of the sql.
C21= SQL*Plus: Release 10.1.0.3.0 - Production on Tue Feb 12 16:26:17 2008 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - 64bit Production With the Partitioning and Data Mining options SQL> 2 3 Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - 64bit Production With the Partitioning and Data Mining options
 
OMS- SQL*Plus: Release 10.1.0.3.0 - Production on Tue Feb 12 16:26:17 2008 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - 64bit Production With the Partitioning and Data Mining options SQL> 2 3 Disconnected from Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - 64bit Production With the Partitioning and Data Mining options

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

GeekManAuthor Commented:
Got it....
needed -s to suppress the chatter and / character to send output to the variable so the code looks like this
var1='sqlplus ${RDBMS_CONNECT} <<-           endsql
             select count(*) from Table1
             /
            exit
endsql

output is:
COUNT(*) ------------ 761612
 I can parse that....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GeekManAuthor Commented:
typo...thats
var1=`sqlplus -s ${RDBMS_CONNECT} <<-        endsql
0
JJSmithCommented:
output is:
COUNT(*) ------------ 761612
 I can parse that....

insert: 'set head off;' before the select and the 'COUNT(*) --------' will not appear on the output.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.