#!/bin/bash
the_date=$1
min_value=$2
max_value=$3
step_value=$4
#the_sql="insert into CSDACM.T_ACM_CDDT_NEW select * from CSDACM.T_ACM_CDDT where JRN_NO>=${step_start} and JRN_NO<${step_end};"
[[ $# -ne 4 ]] && echo -e "please input para:\n$0 date_time min_value max_value step_value\ne.g. $0 20210201 1 10000 50" && exit 1
minus_value=$((${max_value}-${min_value}))
the_count=1
[[ ${step_value} -gt ${minus_value} ]] && echo "step is too long." && exit 1
while true
do
if [ ${the_count} -eq 1 ]
then
step_start=${min_value}
step_end=$((${step_start}+${step_value}))
else
step_start=$((${step_end}))
step_end=$((${step_start}+${step_value}))
fi
echo -e "insert into CSDACM.T_ACM_CDDT_NEW select * from CSDACM.T_ACM_CDDT where JRN_NO>='${step_start}' and JRN_NO<'${step_end}' and AC_DT='${the_date}';\ncommit;\nexec DBMS_LOCK.sleep(15);"
the_count=$((${the_count}+1))
step_next_end=$((${step_end}+${step_value}))
if [ ${step_next_end} -ge ${max_value} ]
then
break
fi
done
step_start=$((${step_end}))
step_end=${max_value}
echo -e "insert into CSDACM.T_ACM_CDDT_NEW select * from CSDACM.T_ACM_CDDT where JRN_NO>='${step_start}' and JRN_NO<='${step_end}' and AC_DT='${the_date}';\ncommit;\nexec DBMS_LOCK.sleep(15);"