Unix 在将值传递给 sql 语句时放置额外的空格/行
我有一个像这样的 unix 脚本:
value1=`sqlplus -s ivr/ivr <<EOF
set heading off;
set feedback off;
set linesize 500;
set serveroutput on;
set wrap off;
SELECT FM.getSequence_n('$b_period', '$t_period', '$opr', '$fran', '$poi_s')
FROM DUAL;
exit;
EOF` ,
参数作为用户的输入。当我使用“ksh -x filename.sh”在调试模式下运行脚本时,我注意到当 unix 脚本将值传递给 select 语句时,它会像这样中断它:
SELECT FM.getSequence_n('
2010/12/01 - 2010/12/31','
2010/12/01 - 2010/12/31','TTSLAP','UWAP','TTSL-LOC')
FROM DUAL
...这给出了错误的输出。当我使用 sqlplus 中传递的值运行相同的 sql 语句并将所有值放在一行中时,我得到正确的输出。
我需要知道为什么 UNIX 将语句分成多行以及如何将其删除。这一直让我做噩梦。首先,我认为值没有正确传递,这就是输出错误的原因。但只有 unix 在传递值时的换行才是错误的原因。请帮忙。
I have a unix script like this:
value1=`sqlplus -s ivr/ivr <<EOF
set heading off;
set feedback off;
set linesize 500;
set serveroutput on;
set wrap off;
SELECT FM.getSequence_n('$b_period', '$t_period', '$opr', '$fran', '$poi_s')
FROM DUAL;
exit;
EOF` ,
The parameters are taken as input from the user. when i run the script in debug mode using 'ksh -x filename.sh' i notice that when the unix script is passing values to the select statement it breaks it like this:
SELECT FM.getSequence_n('
2010/12/01 - 2010/12/31','
2010/12/01 - 2010/12/31','TTSLAP','UWAP','TTSL-LOC')
FROM DUAL
...which gives the wrong output. When i run the same sql statement with the passed values in sqlplus with all the values in a single line i get the correct output.
I need to know why unix is breaking the statement into multiple lines and how can this be removed. This has been giving me nightmares. Firstly i was thinking that values were not being passed correctly that's why output was wrong . But only this linefeed by unix while passing values is the cause of error. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
$b_period
和$t_period
变量似乎包含换行符。如果它们是直接来自用户的输入,您确实应该在使用它们之前先进行一些输入验证。尝试类似的方法
也许您还应该添加进一步的检查,但至少您应该能够通过这种方式过滤掉不需要的字符。
It seems like your
$b_period
and$t_period
variables contain newline characters. If they are input directly from users you really should do some input validation first before using them.Try something like
Probably you should add further check as well, but at least you should be able to filter out unwanted characters this way.
变量的值包括换行符。做这样的事情来检查:
The values of your variables include newlines. Do something like this to check: