0

これが私のシェルスクリプトです:

# 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

行数を取得する方法がない場合は、sqlplus によって返されるエラー コードを使用して、スクリプトをいつ終了するかを判断できますか? 何かご意見は?

ありがとうございました!

4

3 に答える 3

1

sql%rowcount最後の DML ステートメントによって影響を受けた行数を示す which を使用します。

delete from                  
sample             
where                 
sampletime >= to_date('08-30-2011','mm-dd-yyyy') and                 
rownum <= 2;             


if sql%rowcount = 0 then
   dbms_output.put_line('Free');
end if;

commit; 
于 2012-06-01T10:36:35.190 に答える
0

以下をご利用ください。注:-テストされていません

user="*****" 
pass="*****" 
while(true); 
do     
starttime=`date +%s`     
while [[ $((`date +%s` - $starttime)) -lt 2 ]]; 
do         
  rows=`sqlplus -silent $user/$pass@//blabla << EOF             
  whenever sqlerror exit 1 
  SET PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF            
    select count(1) from                  
    sample             
    where                 
    sampletime >= to_date('08-30-2011','mm-dd-yyyy') and                 
    rownum <= 2;             

EOF`         

if [ $rows -neq 0] ; 
then 
    sqlplus $user/$pass@//blabla << EOF1  
    delete  from                  
    sample             
    where                 
    sampletime >= to_date('08-30-2011','mm-dd-yyyy') and                 
    rownum <= 2;             
    commit;
EOF1
else        
echo "Done."         
exit 0;     
fi     
done     
sleep 7 
done 
于 2012-05-31T20:10:27.360 に答える