2011-09-15 90 views
2

这是5月问题:我有内嵌的sqlplus呼叫我的bash的文件,我想传递一个参数如何传递变量在sqlplus在bash命令

这段代码是什么,我想

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语句中使用我的$ id参数(& 1)?

回答

8

只需将&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运行之前。

+0

谢谢你是那个!我意识到这是我在比赛中所做的事情,但我在我的循环中犯了错误... – Baltius

+0

@Baltius:感谢某人的最佳方式是增加他们的声望点。当您看到好的问答时,请使用灰色三角形对其进行投票,网址为http://i.imgur.com/kygEP.png。同时请记住通过按复选标记http://i.imgur.com/uqJeW.png接受最能解决您问题的答案(如果有的话)。祝你好运! – shellter

+0

@Shellter:我会这样做,但它需要15点的声誉才能启用此操作:s我将在稍后执行此操作,因此... – Baltius

相关问题