我可以通过以下方式做到这一点。我编写了一个 shell 脚本,它会逐行读取配置文件,并生成写入新文件的 sql 语句。最后,我从脚本本身执行新的 sql 脚本
INPUT=config.txt
OLDIFS=$IFS
IFS=','
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read sequencename start_value increment_by maxvalue
do
echo "SequenceName : $sequencename"
echo "start value: $start_value"
echo "increment by : $increment_by"
echo "max_value : $maxvalue"
echo "CREATE SEQUENCE $sequencename AS INT START WITH $start_value INCREMENT BY $increment_by MAXVALUE $maxvalue;" >> createsequence.sql
#done < $INPUT
done < <(tail -n +2 $INPUT) #This skips reading the header
IFS=$OLDIFS
config.txt 包含以下几行,
sequencename,start_value,increment_by,maxvalue
tbl1_tbl1id_seq , 1,2 ,50000;
tbl2_tbl2id_seq , 1,2, 50000;
tbl3_tbl3id_seq , 1, 2,50000;