Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Use sqlplus statement inside case sentence

Shell Programming and Scripting


Tags
case, shell, sqlplus

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-01-2013
Vares Vares is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 1 March 2013, 8:29 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
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.


Code:
#/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
Sponsored Links
    #2  
Old Unix and Linux 03-01-2013
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 2 September 2015, 4:18 PM EDT
Location: NM
Posts: 10,532
Thanks: 353
Thanked 881 Times in 819 Posts
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:


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

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

Note the red dash.
The Following 3 Users Say Thank You to jim mcnamara For This Useful Post:
panyam (03-01-2013), Vares (03-01-2013), Yoda (03-01-2013)
Sponsored Links
    #3  
Old Unix and Linux 03-01-2013
Vares Vares is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 1 March 2013, 8:29 AM EST
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Yes!! It was the dash!!

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

Last edited by Vares; 03-01-2013 at 08:29 AM..
    #4  
Old Unix and Linux 03-01-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 3 September 2015, 10:23 AM EDT
Location: Aachen, Germany
Posts: 6,629
Thanks: 113
Thanked 1,822 Times in 1,707 Posts
Pls be aware that the indenting chars need to be <TAB>s in the first case! cf. man bash .
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Connecting sqlplus from UNIX with multiple select statement lovelysethii Shell Programming and Scripting 1 03-01-2013 01:06 AM
SQLPlus Case statement on a substring chris01010 Programming 1 10-16-2012 04:01 PM
how to use sqlplus command inside for loop deepakprasad29@ Shell Programming and Scripting 1 09-29-2011 04:55 AM
Regular expression inside case statement notworking proactiveaditya Shell Programming and Scripting 5 06-17-2011 03:30 PM
multiple lines inside a case statement gotam Shell Programming and Scripting 2 04-23-2010 07:41 AM



All times are GMT -4. The time now is 01:12 PM.