Baltius
Baltius

Reputation: 48

How to pass variables in sqlplus in bash command

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

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)?

Upvotes: 2

Views: 10687

Answers (1)

dogbane
dogbane

Reputation: 274612

Just change &1 to $id. For example:

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. $id will be substituted with the actual value of the parameter i.e. 101 in this case, before sqlplus runs.

Upvotes: 8

Related Questions