X=`sqlplus -s user/pwwd@domain<<eof
set serveroutput on;
set heading off;
DECLARE
change_count number;
BEGIN
Select count(*) into change_count from DBG_INITIATIVES_CHANGE;
dbms_output.put_line(change_count);
END;
/
EXIT;
eof`
if [ $X -gt 0 ]
then
#put ur mail command here
else
echo "count is zero"
fi
Yes the above script is doing what you say it should it will login to sqlplus execute the query and thru dbms output package X will have value of change_count and it will send mail if change_count is greater then zero.
sqlplus -s user/pwwd@domain<<eof in this line give your user name password and domain.run the below code as shell script.
X=`sqlplus -s user/pwwd@domain<<eof
set serveroutput on;
set heading off;
DECLARE
change_count number;
BEGIN
Select count(*) into change_count from DBG_INITIATIVES_CHANGE;
dbms_output.put_line(change_count);
END;
/
EXIT;
eof`
if [ $X -gt 0 ]
then
mailx -s "count is greater than zero" abcd@xyz.com
else
echo "count is zero"
fi
X=`sqlplus -s user/pwwd@domain<<eof
SET HEAD OFF FEED OFF PAGES 0
Select count(*) from DBG_INITIATIVES_CHANGE;
eof`
if [ $X -gt 0 ]
then
mailx -s "count is greater than zero" abcd@xyz.com
else
echo "count is zero"
fi
Execute the sqlplus command and store it's output into variable X.
The sqlplus command is started with the -s option that means silent mode.
The user and passord for connection to the database is specified on the command line user/pwwd@domain
The syntax <<eof specifies that the input for the sqlplus command is included in the script starting next line and ending with the line eof
Aigles is absolutely right what he has explained i would like to add few lines.
sqlplus -s user/pwwd@domain
this line of code will invoke sqlplus and will login to database with "user" and "passwd" in "domain".
now you are in sqlplus and run procedure,functions etc as you can do it in
sqlplus session.
<<eof
.......
.........
......
eof
this is known as here document.
if we do any print as in unix is echo and sqlplus is dbms_output.put_line will come to shell variable X.