Last active
January 2, 2016 16:39
-
-
Save jgcasta/8331385 to your computer and use it in GitHub Desktop.
Delete Oracle records from a bash shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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