简体   繁体   English

检索SQLPLUS查询结果并将其保存到变量bash中

[英]Retrieve and save SQLPLUS query result into a variable bash

I am trying to save the response of a query made through SQLPLUS and save it in a local variable, but when i execute the following code, i get the path as output instead of the value of the query, could u please help me? 我正在尝试保存通过SQLPLUS进行的查询的响应并将其保存在本地变量中,但是当我执行以下代码时,我将路径作为输出而不是查询的值,您能帮我吗? I don't know what am i doing wrong: 我不知道我在做什么错:

    #!/bin/bash

SQLPLUS="<Path to sqlplus> -s user/passwd"
X=$SQLPLUS<<EOF_SQL_1
    set heading off;
    select table1 from table 2 where parameter ='Properties';
exit;
EOF_SQL_1
echo  $X

The result of this script is " -s user/passwd" when it should be the esult of the query I made. 该脚本的结果应为我进行查询的结果时为“ -s user / passwd”。 Please tell me what am I doing wrong :S 请告诉我我在做什么错了:S

using heredoc and command substitution in the same command would not be recommended, the easier is to use a function 不建议在同一命令中使用heredoc和命令替换,更容易使用函数

fun_sql() {
    sqlplus user/passwd@tnsname <<EOF
...
EOF
}

X=$(fun_sql)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM