SQL*Plus如何在一个语句中执行环境设置和查询
我执行以下查询,该查询返回一个值,并且可以正常工作。
echo "select myquery ;" | sqlplus user/pass@dbase | | head -4 | tail -1
问题是,当返回的一个值太大时,它会被多行分开,因此我进一步使用的ETL工具会遇到问题。 因此,我尝试使用Linesize选项,但无法将其与查询结合使用。
如果我连接到sqlplus并运行: 设置LINESIZE 3200
后跟选择MyQuery;
输出很好,但我无法在Echo语句中组合它们。 我以不同的方式尝试了:
echo "SET LINESIZE 3200 / select myquery ;" | sqlplus user/pass@dbase | | head -4 | tail -1
有什么想法吗?
谢谢!
I execute the following query which returns one value and it works fine.
echo "select myquery ;" | sqlplus user/pass@dbase | | head -4 | tail -1
The issue is that when the one value returned is too large it gets split in multiple rows thus the ETL tool that I further use gets problems.
Therefore I have tried to use the linesize option but I am not able to combine it with the query.
If I connect to sqlplus and run:SET LINESIZE 3200
followed by select myquery ;
the output is fine but I am not able to combine them in the echo statement.
I have tried in different ways, for example:
echo "SET LINESIZE 3200 / select myquery ;" | sqlplus user/pass@dbase | | head -4 | tail -1
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HEREDOC(如 @Philippe的答案所示)将更容易阅读和维护,但是如果出于某种原因您真的想将其保持一行,则可以将
-e
flag添加到<代码> echo 并嵌入新行:或使用
printf
:(在两者中,我从原始版本中取出了额外的
|
)为了避免需要并向输出进行尾声:
或使用各种
set
选项组合:-s
抑制横幅;从您使用的头部/尾巴值中,我想您已经拥有它并且没有显示它。 (我通常也会扔进-L
,因此,如果凭据错误,它不会卡住。)其他set
命令命令删除列标题和“”选择了1行。”信息。尽管总体上是更长的单个命令行,但它具有不操纵/操纵您可能会收到的任何错误输出的优势。
或作为Heredoc:
A heredoc (as shown in @Philippe's answer) is going to be easier to read and maintain, but if for some reason you really wanted to keep it in one line you could add the
-e
flag toecho
and embed new lines:or use
printf
:(In both I've taken out the extra
|
from your original version)You can extend this to avoid the need to head and tail the output:
or with the various
set
options combined:The
-s
suppresses the banner; from the head/tail values you're using I imagine you already have that and just didn't show it. (I'd usually throw in-l
as well, so it doesn't get stuck if the credentials are wrong.) The otherset
commands remove the column headings and "1 row selected." message.While that's a longer single command line overall, it has the advantage of not manipulating/mangling any error output you might get.
Or as a heredoc:
您能尝试一下:
Can you try this :