In the below shell script I am connecting to DB and getting the count value.
In the below code I am not getting the correct count value. Instead it is returning 185 (random int value)
but the actual count value which is supposed to be returned is 2233.
If I replace return with echo, it prints the correct 2233 value. But alertCount variable is assigned 0 value.
findAlertCount(){
(
count=$(sqlplus -s ${DBA_ORACLE_USER}/${DBA_ORACLE_PWORD}@${ORACLE_SID} <<END
#connect ${DBA_ORACLE_USER}/${DBA_ORACLE_PWORD}@${ORACLE_SID}
set serveroutput on
set linesize 1000
set heading off
set feedback off
SELECT count(1)
FROM mytable
WHERE mycolumn IS NOT NULL;
exit;
END
)
return "$count"
)
}
findAlertCount
alertCount=$?
echo "alertCount" $alertCount
//This prints 185 if return is used. And prints 0 if echo is used.