your end_ct contain the value inside the curly brackets {} i.e.
"TRIM(DESCR
----------
END CAT"
so end_ct and END CAT values are different and the output is value not found.. so check out your sql query and the result its returning. right now ur sql query is returning "TRIM(DESCR
----------
END CAT" value and not "END CAT".
yeah, i have seen this. but it is obvious that it will return column name along with the value.
end_ct=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF
select trim(description) from bravo_statistics
where trunc(time_stamp)=trunc(sysdate)-5
and description='END CAT';
how to get rid off from this situation now, please help
---------- Post updated at 10:07 AM ---------- Previous update was at 10:01 AM ----------
i have used another variable to check the value of end_ct and comparing these 2 variables now. it is returning the exact value which i require
a=$end_ct
and further my condition is
if [ "$end_ct" = "$a" ] && [ $emtr_cnt -eq 1 ] ; then
echo $end_ct
else
echo "value not found"
fi
but whille using && condition it is showing some other error:
bravo_main_refresh.sh: test: unknown operator ----------
i am sorry for this, but my logic is incorrect for the first statement too. because i need to compare value with END CAT. please suggest how to compare value of a variable returning from a select statement.
just send the output to a temporary file instead of storing in a variable using
sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF > sql_output.txt
select trim(description) from bravo_statistics
where trunc(time_stamp)=trunc(sysdate)-5
and description='END CAT';
EOF
end_ct=`sed -n '3p' sql_output.txt`
just check the content of the sql_output.txt file and see in which line the output of the sql query occurs i.e. the END CAT value comes in which line and accordingly use the line number in the sed command.. i assumed the actual output (excluding the column name and the ---------) appears in the 3rd line so i have used 3p in the sed command. change the 3p to appropriate line number after checking the value inside sql_output.txt.
---- edit: below statement is incorrect as Little pointed out. I somehow missed the >> -----
You are never reading the sql_output.txt file that is created by the first sqlplus statement and it gets overwritten by the second.
end_ct=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF > sql_output.txt
select trim(description) from bravo_statistics
where trunc(time_stamp)=trunc(sysdate)-5
and description='END CAT';
EOF`
with just
sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF > sql_output.txt
select trim(description) from bravo_statistics
where trunc(time_stamp)=trunc(sysdate)-5
and description='END CAT';
EOF
and similarly
emtr_cnt=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF >> sql_output.txt
select count(*) from mrs.bill_cal
where trunc(actual_run_date)=trunc(sysdate)-4;
EOF`
with just
sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF >> sql_output.txt
select count(*) from mrs.bill_cal
where trunc(actual_run_date)=trunc(sysdate)-4;
EOF
and u can replace a and b with end_ct and emtr_cnt respectively if u want. and remove the
echo $end_ct and
echo $emtr_cnt
and put it after the two sed commands to c the values of these variables to be sure.
otherwise everything is fine.
---------- Post updated at 11:07 AM ---------- Previous update was at 11:02 AM ----------
its not getting overwritten but the second sql output is appended to the sql_output.txt file. so the sql_output.txt is having the output of both the sql queries.
> overwrites to the existing file
>> append to the file