Skip to content

Instantly share code, notes, and snippets.

@jgcasta
Last active January 2, 2016 16:39
Show Gist options
  • Save jgcasta/8331385 to your computer and use it in GitHub Desktop.
Save jgcasta/8331385 to your computer and use it in GitHub Desktop.
Delete Oracle records from a bash shell script
#!/bin/bash
#Delete Oracle table since 1 natural year
#
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/schema@db
$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