Use sqlplus statement inside case sentence


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use sqlplus statement inside case sentence
# 1  
Old 03-01-2013
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
# 2  
Old 03-01-2013
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.
These 3 Users Gave Thanks to jim mcnamara For This Post:
# 3  
Old 03-01-2013
Yes!! It was the dash!!

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

Last edited by Vares; 03-01-2013 at 09:29 AM..
# 4  
Old 03-01-2013
Pls be aware that the indenting chars need to be <TAB>s in the first case! cf. man bash.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SQLPLUS command with more than 1 select statement

Hi all, I'm using below code processId=`sqlplus -s ${sysuser}/${syspwd} <<CHK_PROCESS whenever sqlerror exit sql.sqlcode; set head off feedback off echo off pages 0 SELECT PROCESS_ID FROM LSHADMIN.DATA_DOMAIN WHERE DOMAIN_NAME = '${tabname}' ... (8 Replies)
Discussion started by: Pratiksha Mehra
8 Replies

2. Shell Programming and Scripting

Sqlplus inside shell script writing to tmp file

Hi, facing an issue while calling sqlplus inside shell script. It for some reason goes to tmp file to write something and i get error as permission denied as i dont have access there. ANy idea why sqlplus writes in /tmp and how to change or stop this ? (2 Replies)
Discussion started by: rushikeshs
2 Replies

3. Shell Programming and Scripting

Error with nested if within an sqlplus task inside

Hi ALL, I am receving a "strange" error using a nested if within an sql operation inside: ./dom.ksh: syntax error at line 80 : `then' unmatched This is all my script code: in bold the step receiving the error. Any help would really aprrecieted ......! **** I have tried all the... (2 Replies)
Discussion started by: AndreaCecco
2 Replies

4. Shell Programming and Scripting

Connecting sqlplus from UNIX with multiple select statement

hi, i have a requirement where i need to connect sqlplus from unix and i am able to do so by following command: cust_count=`sqlplus -s $ORACLE_USER/$ORACLE_PASS@$ORACLE_SID << EOF set pagesize 0 set feedback off set verify off ... (1 Reply)
Discussion started by: lovelysethii
1 Replies

5. Programming

SQLPlus Case statement on a substring

Hi, I have an SQL query that returns a substring of a field and I want to work a case statement on it, but either I get a syntax error or in it's current manifestation the case is ignored all together. select distinct dbms_lob.substr(msg_body,1,4) as networkId, A_STATUS, count(*) from... (1 Reply)
Discussion started by: chris01010
1 Replies

6. Shell Programming and Scripting

how to use sqlplus command inside for loop

I tried this: for region in 'raj' 'kt' 'kol' 'krl' 'chn' 'dl' 'hr' 'bih' 'ap' do sqlplus -s huw$region/`echo $region`huw#321@huw$region<<! set serveroutput on begin select count(*) from tcd_preferred_cust_201109 end; / exit; done but the error shows like: Syntax error at line 4 :... (1 Reply)
Discussion started by: deepakprasad29@
1 Replies

7. Shell Programming and Scripting

Regular expression inside case statement notworking

I have the following script: For catching errors like: But the regular expression ERROR*memory inside case doesn't seem to be working. The output of bash -x scriptname is: Please help (5 Replies)
Discussion started by: proactiveaditya
5 Replies

8. Shell Programming and Scripting

multiple lines inside a case statement

echo "please enter ur choice.. 1. Make a file. 2. Display contents 3. Copy the file 4. Rename the file 5. Delete the file 6. Exit" read choice case $choice in 1 ) echo enter the file name read fname if then echo... (2 Replies)
Discussion started by: gotam
2 Replies

9. UNIX for Dummies Questions & Answers

Script to ask for a sentence and then count number of spaces in the sentence

Hi People, I need some Help to write a unix script that asks for a sentence to be typed out then with the sentence. Counts the number of spaces within the sentence and then echo's out "The Number Of Spaces In The Sentence is 4" as a example Thanks Danielle (12 Replies)
Discussion started by: charlie101208
12 Replies
Login or Register to Ask a Question