如何将结果从 SQLPlus 存储到 shell 变量 [英] How to store result from SQLPlus to a shell variable

查看:85
本文介绍了如何将结果从 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.

这篇关于如何将结果从 SQLPlus 存储到 shell 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆