Skip to content

Instantly share code, notes, and snippets.

@jgcasta
Created February 22, 2013 11:50
Show Gist options
  • Save jgcasta/5012941 to your computer and use it in GitHub Desktop.
Save jgcasta/5012941 to your computer and use it in GitHub Desktop.
Delete oracle old entries shell script
#!/bin/bash
# Delete 1 year before today
#
# 20/02/2013 v1.0
#
#
ANO=$(date +%Y)
ANTERIOR=$[ANO-1]
FBORRADO=$(date +%d-%m-$ANTERIOR)
MES=$(date +%m)
MESANTERIOR=$[MES-1]
if [ $MESANTERIOR -lt 1 ]; then
MESANTERIOR=12
ANO=$ANTERIOR
fi
FBORRADO2=$(date +%d-$MESANTERIOR-$ANO)
SENTENCIA1="delete from historico where HIST_FECHAALTA < to_date('$FBORRADO','dd-mm-yy');"
sqlplus -s /nolog << EOF
set echo on
connect user/pass@dest
$SENTENCIA1
commit;
exit sql.sqlcode
EOF
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment