bash 如何在bash命令中传递sqlplus中的变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7431355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:47:17  来源:igfitidea点击:

How to pass variables in sqlplus in bash command

bashparameterssqlplus

提问by Baltius

Here is may problem : I have inline sqlplus call in my bash file and I would like to pass it a parameter

这里可能有问题:我的 bash 文件中有内联 sqlplus 调用,我想向它传递一个参数

this code is what I'm trying

这段代码是我正在尝试的

c_id=`sqlplus -S $login/$password  $id << EOF
    set pagesize 0
    set verify off
    set head off
    set feedback off
    SELECT id from bdd.table where ID not in (select id from bdd.TMP_table) and id > &1 and ROWNUM <= 1000 order by id;
    exit;
    EOF`

how can I use my $id parameter in my where statement (&1)?

如何在 where 语句 (&1) 中使用 $id 参数?

回答by dogbane

Just change &1to $id. For example:

只需更改&1$id. 例如:

id=101
c_id=`sqlplus -S $login/$password  << EOF
    set pagesize 0
    set verify off
    set head off
    set feedback off
    SELECT id from bdd.table where ID not in (select id from bdd.TMP_table) and id > $id and ROWNUM <= 1000 order by id;
    exit;
    EOF`

Bash will perform parameter substitution. $idwill be substituted with the actual value of the parameter i.e. 101in this case, before sqlplusruns.

Bash 将执行参数替换。$id将被替换为参数的实际值,即101在这种情况下,在sqlplus运行之前。