Sql query output count

Hi Team,
below sql rerturn 20 records, the result set i am going to assign to one variable and it showing count is 1.
and i don't use count() in sql query... based on count, i need to fail the script.

No_of_step=`echo ${g_count} | wc -l`

function gf_count()
{
g_count=`sqlplus -s scott/scott@orcl << !END_SQL
whenever oserror exit 99
whenever sqlerror exit 99
set echo off
set heading off
set feedback off
set pagesize 0
set line 500
select ename||sal from emp
/
exit
!END_SQL`
}

Can you help me on this one ?

Could you share the returned result of the sqlplus using code tags, please.

Thanks for quick reply

mk@test2
mk@test3
mk@test4
mk@test5
mk@test6

what do you get if (using code tags)

echo "[${g_count}]"

thanks for quick reply and it is working fine and small help to assign the value to variable. it not getting output

cnt=`echo "[${g_count}]" |wc -l`

hm.... I don't know if it's working fine or not getting output...
I asked for the output of echo "[${g_count}]" only - without |wc -l ..
Please do provide the above...
Also try:

function gf_count()
{
g_count=$(sqlplus -s scott/scott@orcl << !END_SQL
whenever oserror exit 99
whenever sqlerror exit 99
set echo off
set heading off
set feedback off
set pagesize 0
set line 500
select ename||sal from emp
/
exit
!END_SQL
)
}
2 Likes

count is dispalying as expected ,but i need to store the values into one variable for comparsion purpose.

see the last update to try...

1 Like

Thanks a lot it is working fine :slight_smile:

1 Like