Use sqlplus statement inside case sentence

Hello,

I have a problem. I want to launch a different sql queries for different shell parameter values, something like this.

#/bin/bash
case $1 in
   
   "A") 
            sqlplus -s user/pass << SQL
 
                query A;
            SQL

    "B") sqlplus -s user/pass << SQL2

              query B;
          SQL2

     *) echo "something"
  

esac

The problem is that the first sqlplus connection does not finish (with SQL string) and the rest of the code is considered "A" case, esac included. So case statment is bad defined.

Anyone can help me? I was looking inside this forum and I didn�t find something similar

Thanks a lot!! and sorry about me english

The ending SQL is not seen. It needs to be in the leftmost column. Or structured differently Your here doc need to be one of these:

           sqlplus -s user/pass <<-SQL
 
                query A;
            SQL

## OR this way
           sqlplus -s user/pass << SQL
 
                query A;
SQL

Note the red dash.

3 Likes

Yes!! It was the dash!!

Thank you so much!! And you understood me, that was nice

Pls be aware that the indenting chars need to be <TAB>s in the first case! cf. man bash .