【问题标题】:How to pass variables in sqlplus in bash command如何在bash命令中传递sqlplus中的变量
【发布时间】:2011-09-15 13:06:58
【问题描述】:

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

这段代码是我正在尝试的

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`

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

【问题讨论】:

    标签: bash parameters sqlplus


    【解决方案1】:

    只需将&amp;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 将执行参数替换。在这种情况下,$id 将替换为参数的实际值,即 101,在 sqlplus 运行之前。

    【讨论】:

    • 谢谢你!我意识到这是我在开始时所做的,但我的循环中有错误......
    • @Baltius :感谢某人的最佳方式是增加他们的声望点。当您看到好的问答时,请使用灰色三角形i.imgur.com/kygEP.png 投票。还记得通过按复选标记i.imgur.com/uqJeW.png 来接受最能解决您的问题的答案(如果有)。祝你好运!
    • @Shellter :我会这样做,但我需要 15 点声望才能启用此操作:我稍后会这样做......
    • 您可以接受只有 1 分的答案(上面的第二个链接)。祝你好运。
    猜你喜欢
    • 2013-09-28
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多