How can I return the number of rows affected in sqlplus to a shell script?

Posted by jessica on Stack Overflow See other posts from Stack Overflow or by jessica
Published on 2012-05-31T17:05:38Z Indexed on 2012/06/01 10:40 UTC
Read the original article Hit count: 262

Filed under:
|
|
|

Here is my shell script:

# Deletes data from the 'sample' table starting August 30, 2011.
# This is done in stages with a 7 second break every 
# 2 seconds or so to free up the database for other users. 
# The message "Done." will be printed when there are 
# no database entries left to delete.

user="*****"
pass="*****"
while(true); do
    starttime=`date +%s`
    while [[ $((`date +%s` - $starttime)) -lt 2 ]]; do
        sqlplus $user/$pass@//blabla <<EOF
            whenever sqlerror exit 1
            delete from 
                sample
            where
                sampletime >= to_date('08-30-2011','mm-dd-yyyy') and
                rownum <= 2;
            commit;
EOF
        rows = ???
        if [ $rows -eq 0 ] ; then
        echo "Done."
        exit 0;
    fi
    done
    sleep 7
done

If there is no way to get the number of rows, maybe I can use an error code returned by sqlplus to figure out when to end the script? Any thoughts?

Thank you!

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about bash