i have this script that retrieves a parameter (a number) from a SQL query and assigns it to a variable. there are two options - either the SQL query finds a value and then the script preforms echo "the billcycle number is $v_bc", or it doesnt find a value and it suppose to echo "no billcycle parameter found". im having a problem with the if condition.
this is what i came up with:
#!/bin/bash
v_bc=`sqlplus -s /@bscsprod <<EOF
set pagesize 0
select billcycle from bc_run
where billcycle not in (50,16)
and control_group_ind is null
and billseqno=6043;
EOF`
if [ -z "$v_bc" ]; then echo no billcycle parameter found
else echo "the billcycle parameter is $v_bc"
fi
when billseqno=6043, then it means that v_bc=25, and when i run the script, the result is: "the billcycle parameter is 25". which is what i ment it to do. when i set billseqno=6042, according to the above SQL query, v_bc will get no value, therefore what i want it to do is echo "no billcycle parameter found". instead i get
"the billcycle parameter is
no rows were selected".
any suggestions ?
thanks very much Assaf.