issues with sql inside if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting issues with sql inside if statement
# 1  
Old 10-12-2012
issues with sql inside if statement

Hi,

I have problem with the following code. My IF block is not executed. And I see "syntax error near unexpected token `)'" error for line "EOF" in the stats_function().
but when I comment the IF block I don't see this error.

Kindly help me with this issue.

Code:
clean_function()
{
count_clean=$(sqlplus -s username/password@SID<<-EOF
SET HEADING OFF
SET FEEDBACK OFF
SET PAGES 0
select count(*) from tableA;
quit
EOF
)
echo  $count_clean
}
count2_clean=$(clean_function)
echo $count2_clean


if [ $count2_clean -ne 0 ];then
  sqlplus -s $(sqlplus -s username/password@SID<<-EOF
  SET HEADING OFF
  SET FEEDBACK OFF
  SET PAGES 0
  delete from tableA;
  quit
  EOF
fi
######################## RUN THE SCRIPT TO LOAD THE DB ######################
sh dbloadscript

######################## CHECK THE STATUS OF THE DB ###########################
stats_function()
{
count_status=$(sqlplus -s username/password@SID<<-EOF
SET HEADING OFF
SET FEEDBACK OFF
SET PAGES 0
select count(*) from tableA where status=a;
EOF
)
return $count_status
}

# 2  
Old 10-12-2012
which editor you are using. Normally editors will show what you are missing. specially with the ( and {..Smilie(i am using Notepad++)

there is no closing bracket for below highlighted..(

Code:
if [ $count2_clean -ne 0 ];then
  sqlplus -s $(sqlplus -s username/password@SID<<-EOF
  SET HEADING OFF
  SET FEEDBACK OFF
  SET PAGES 0
  delete from tableA;
  quit
  EOF
fi

# 3  
Old 10-12-2012
Sorry that was a Typo
actually in the script it is:
sqlplus -s username/password@SID<<-EOF
# 4  
Old 10-12-2012
Quote:
Originally Posted by babom
And I see "syntax error near unexpected token `)'" error for line "EOF" in the stats_function().
[/CODE]
Your error clear mentions that ) is missing.
# 5  
Old 10-12-2012
yes.. that is why I am confused.... I have checked my actual code in notepad++... the braces are fine.... like I said earlier if i comment IF statement ... I don't have the error... but with the IF statement I get that error....
my IF statement looks like ... the first post had a typo

Code:
if [ $count2_clean -ne 0 ];then
 sqlplus -s username/password@SID<<-EOF
 SET HEADING OFF
 SET FEEDBACK OFF
 SET PAGES 0
 delete from tableA;
 quit
 EOF
fi

# 6  
Old 10-12-2012
Does your closing EOF have a tab character in front of it? The dash before the first EOF means ignore leading tabs in front of the closing EOF.
On my system, it did not work if there were spaces in front of the closing EOF.

Thanks Elixir!

Last edited by gary_w; 10-12-2012 at 11:04 AM..
# 7  
Old 10-12-2012
try using double quotes or [[


Code:
if [[ $count2_clean -ne 0 ]];then

or
Code:
if [ "$count2_clean" -ne 0 ];then

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command in inside awk statement

Hello can you please help me with below script which is meant to delete clients from multiple netbackup policies I want to run a command insdie awk statement apparelnlty this script is not working for me for i in $( cat clients_list) do bppllist -byclient $i | awk... (6 Replies)
Discussion started by: Sara_84
6 Replies

2. Shell Programming and Scripting

Multiple conditions inside if statement

I was trying to write multiple conditions inside the if statement but its not working. export VAR_NM=abc.txt export CURR_DT=20131011 export PREV_DT=20131012 if && then echo "Yes" else echo "NO" fi It should return Yes but returning NO always.Appreciate any help. (3 Replies)
Discussion started by: dr46014
3 Replies

3. Shell Programming and Scripting

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 ... (3 Replies)
Discussion started by: Vares
3 Replies

4. Shell Programming and Scripting

Multiple conditions inside my if statement

Hello, I am using shell scripting and I am recieving odd results from my if statement if I want it to enter the loop only if L1 is equal to zero and one of the other criteria are filled, however it is entering at other times as well. What can i do to fix this? i tried seperating it... (6 Replies)
Discussion started by: ryddner
6 Replies

5. Shell Programming and Scripting

Bash Script Issues (If statement for file copying)

Writing a bash script for use with Geektool, pulls the battery info, and shuffles images around so that an Image geeklet can display the correct expression as the desktop background. (Eventually I intend to make it more intricate, based on more variables, and add more expressions) I'm extremely... (1 Reply)
Discussion started by: The_Ardly374
1 Replies

6. Shell Programming and Scripting

Read from user inside a while statement

Hi there I want to ask to a user something about each line of a file. This is my code: #cat test.txt first line second line third line #cat test.sh #!/bin/ksh read_write () { echo "Do you want to print the line (YES/NO)?\n" read TEST case ${TEST} in YES) return 0;; ... (3 Replies)
Discussion started by: tirkha
3 Replies

7. Shell Programming and Scripting

if inside while statement (PLZ HELP)

hey guys i need some help here i am trying to do a bash shell script to get a parent PID and then search for all childs and kill them all without killing the parent, my problem is in the loop it seems that i dont know how to make a if statment inside a while statment it does not give me what i... (5 Replies)
Discussion started by: q8devilish
5 Replies

8. Shell Programming and Scripting

how to pass a variable to an update sql statement inside a loop

hi all, i am experiencing an error which i think an incorrect syntax for the where clause passing a variable was given. under is my code. sqlplus -s ${USERNAME}/${PASSWORD}@${SID} << END1 >> $LOGFILE whenever sqlerror exit set serveroutput on size 1000000 declare l_rc ... (0 Replies)
Discussion started by: ryukishin_17
0 Replies

9. Shell Programming and Scripting

How to call an sql script inside a while statement in KSH

Hi all, I'm trying to run an sql inside a loop which looks like this #!bin/ksh while IFS=, read var1 var2 do sqlplus -s ${USERNAME}/${PASSWORD}@${ORACLE_SID} << EOF insert into ${TABLE} ( appt_date ) values ( '${var1 }' ); ... (6 Replies)
Discussion started by: ryukishin_17
6 Replies

10. Shell Programming and Scripting

sql inside a script

Hi, In a KSH script i have to run a sybase query and get the count into a unix variable. How can i do that? Your help is much appriciated. Thanks, sateesh (4 Replies)
Discussion started by: kotasateesh
4 Replies
Login or Register to Ask a Question