如何将结果从 SQLPlus 存储到 shell 变量
我的要求是将 sqlplus 操作的结果存储到我的 shell 脚本中的一个变量中.我需要在我的 .sh 文件中执行以下操作的结果
My requirement is to store the result of an sqlplus operation into a variable in my shell script. I need the result of the following operation which is in my .sh file
sqlplus 'user/pwd' @test.sql
我已经试过了
testvar = 'sqlplus 'user/pwd'
@test.sql'
但这不起作用.
我改成
testvar=sqlplus foo/bar@SCHM @test.sql
它说
SQL*Plus:: not found [No such file or directory]
我试过
testvar=$(sqlplus foo/bar@SCHM
@test.sql)
它给出了同样的错误.当我尝试没有像下面这样的变量赋值
and it gives the same error. When I try without the variable assignment like below
sqlplus foo/bar@schm @test.sql
效果很好
使用反引号:
testvar=`sqlplus foo/bar @test.sql`
或者这应该是句法上的眼中钉:
or should that be of syntactical eyesore:
testvar=$(sqlplus foo/bar @test.sql)
您清楚地知道使用正确的 sql*plus 命令来限制多余的输出,是吗?:) 当然要注意反引号会折叠输出的空白.
You clearly know to take the right sql*plus commands to limit superfluous output, yes? :) and of course beware the backticking will collapse the whitespace of the output.