将变量从sh传递到sql declare-a数组[2] for((i=0;i
如果要从输入创建将变量从sh传递到sql declare-a数组[2] for((i=0;i,sql,bash,shell,Sql,Bash,Shell,如果要从输入创建file.sql,则不需要数组。可以在相同的for循环中读取和写入 declare -a array[2] for (( i=0; i<3; i++ )) do read array[$i] done for (( n=0; n<3; n++ )) do echo -e "From Table[$n]: ${array[$n]}\n " ; done sqlplus owner/pass@db << ENDOFSQL @file.sql
file.sql
,则不需要数组。可以在相同的for循环中读取和写入
declare -a array[2]
for (( i=0; i<3; i++ ))
do
read array[$i]
done
for (( n=0; n<3; n++ ))
do
echo -e "From Table[$n]: ${array[$n]}\n " ;
done
sqlplus owner/pass@db << ENDOFSQL
@file.sql
exit;
ENDOFSQL;
您还应该能够完全跳过输入文件,并将for循环的输出直接传输到sqlplus
for (( i = 0; i < 3; i++ )); do
read a
echo "From Table[$i]: $a"
done >file.sql
sqlplus owner/pass@db @file.sql
((i=0;i<3;i++)的for;do
读一本
echo“来自表[$i]:$a”
完成| sqlplus所有者/pass@db
Sample input/output needHi,谢谢你的回答。如何将该文件传递给sqlplus/plsql?@Dave根据,你可以在命令行中将其命名为sqlplus…@file.sql
。我相应地更新了我的答案。
for (( i = 0; i < 3; i++ )); do
read a
echo "From Table[$i]: $a"
done | sqlplus owner/pass@db