执行sql语句并将值存储在变量中 [英] Executing sql statement and storing value in variable
本文介绍了执行sql语句并将值存储在变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 shell 脚本,它试图执行一个简单的 sql 语句并打算将结果存储在单个变量中.但我无法做到这一点.我正在使用 Cygwin 并打算在 unix 中使用它.找到下面的脚本
I have a shell script which is trying to execute a simple sql statement and intend to store the result in single variable. But i am unable to do it.I am using Cygwin and intended to use it in unix. Find below script
echo "executing a script.."
var=(sqlplus cimnewuser/cimnewuser@cimnew
select ID from catalog where tablename='MCT_35618';
exit)
echo "$var"
它给了我错误.我是在 sql 中执行 sql 操作的新手.
it is giving me error. I am new to executing sql manipulation in sql.
提前致谢!!
推荐答案
您缺少一个 $
.
试试:
var=$(sqlplus cimnewuser/cimnewuser@cimnew
select ID from catalog where tablename='MCT_35618';
exit)
或者,您可以使用反引号:
Alternatively, you can use backticks:
var=`sqlplus ...`
这篇关于执行sql语句并将值存储在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文