如何将结果从 SQLPlus 存储到 shell 变量

编程入门 行业动态 更新时间:2024-10-21 09:45:08
本文介绍了如何将结果从 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 变量

本文发布于:2023-10-18 11:03:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504053.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   如何将   SQLPlus   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!