我在循环中用Bash构建一个字符串。循环从两个文件中的行中处理的数据如下所示:
字符串的第一部分是文件1中的一行,如下所示:
SOME_PACKAGE第二部分是文件2的一行,如下所示:
someFunction('some',parameters,here)最后的输出在两个字符串之间有一个点:
1 SOME_PACKAGE.someFunction('some',parameters,here)1在这里很重要。马上解释一下。
字符串是在一个双while循环中形成的。
while read line1 ; do
while read line2 ; do
stringArray=($line2)
string=$line1.${stringArray[1]}
sqlplus -s /nolog > /dev/null 2>&1 <<EOF
connect user/password@db_instance
variable rc refcursor;
SPOOL ${line1}_${stringArray[0]}.DATA
exec :rc := $string;
print rc;
spool off
exit
EOF
done < file2.txt
done < file1.txt然后将此字符串传递给SQL_Plus,SQL_Plus应该退出如下命令:
SQL> variable rc refcursor;
SQL> exec :rc := SOME_PACKAGE.someFunction('some',parameters,here);
SQL> print rc;直到现在,一切都很好。但是我在someFunction旁边有一个更复杂的参数。现在看起来是这样的:
SOME_PACKAGE.someFunction('some',parameters,here,'and 2 more',NULL)似乎传递给SQL*Plus的变量在第一个空间结束.所以看起来:
SOME_PACKAGE.someFunction('some',parameters,here,'and据我所知,我不应该在变量中传递空格,或者如果我想这样做,我应该用引号来包装它们:"",但是我应该把这些引号放在哪里才能传递最后的vatiable给SQL*Plus,而不需要那些引号呢?或者你们还提出了什么解决方案?
发布于 2014-12-10 13:43:48
由于@arco444 444,答案很简单。
所有这些发生的原因是内部字段分隔符,该分隔符被设置为默认值。
我所做的是:
我改变了file2的外观
1 SOME_PACKAGE.someFunction('some',parameters,here,'and 2 more',NULL)至
1§SOME_PACKAGE.someFunction('some',parameters,here,'and 2 more',NULL)我在循环前后添加了一些ILS更改,所以最后的代码如下所示:
oldifs=$IFS
IFS="§"
while read line1 ; do
while read line2 ; do
stringArray=($line2)
string=$line1.${stringArray[1]}
sqlplus -s /nolog > /dev/null 2>&1 <<EOF
connect user/password@db_instance
variable rc refcursor;
SPOOL ${line1}_${stringArray[0]}.DATA
exec :rc := $string;
print rc;
spool off
exit
EOF
done < file2.txt
done < file1.txt
IFS=$oldifs现在一切都很有魅力。
https://stackoverflow.com/questions/27401181
复制相似问题