Error in Comparison value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in Comparison value
# 1  
Old 02-12-2013
Error in Comparison value

Hi I have written below Script
Code:
IFS=:
while read emp_id_ name manager department;
do echo "$emp_id_";
count=`sqlplus -s sys/orcl as sysdba << EOF
select count(*) from employee where emp_id = ('$emp_id_');
exit;
EOF`;
echo "$count" ;
if [ $count == 1 ] ; then echo "data exist" else echo "not exist" ; fi;
done < employee_data.txt

In employee_data file data as below:-
Code:
1:rushabh:4:IT

I employee table data is already there with emp_id = 1

now when I am comparing data its returning not exist
but it should return "data exist"

where is the problem in my script ?

please help me out from this problem?
thanks in advance

Last edited by Franklin52; 02-12-2013 at 03:10 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 02-12-2013
Please post the output of the script.
Specially echo "$count"

BTW,
1) ";" only required as the command terminator if multiple commands are on the same line
2) use -eq as the integer equality comparison instead ==
3) In select query, you should use emp_id = $emp_id_ ( Assuming the datatype is Number)
# 3  
Old 02-12-2013
Output for $count is as below
Code:
count(*)
----------
1

---------- Post updated at 02:10 AM ---------- Previous update was at 02:07 AM ----------

I am reading data from text file and comparing it with SQL Statement at the end
Code:
emp_id = ('$emp_id_')

is it ok?


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.


---------- Post updated at 02:12 AM ---------- Previous update was at 02:10 AM ----------

I also use -eq operation for comparison but still its not working..i think there is problem in comparison between integer and string...

Last edited by Franklin52; 02-12-2013 at 03:11 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 02-12-2013
So now you can see the $count is not equals to just "1". there are column headers and other stuffs along with the value.

you must do "set heading off" inside sqlplus.
You might also require to suppress the white spaces before and after the value either db level or shell level.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help about comparison

Hello folks, I have two files, which have usernames, I want to see the contents of file1.txt which is missing in file2.txt and another comparison file2.txt contents which is missing in file1.txt. please suggest. file1.txt user u2 u8 a9 p9 p3 u4 z8 aaa ahe oktlo (7 Replies)
Discussion started by: learnbash
7 Replies

2. UNIX for Dummies Questions & Answers

comparison

hi guys i need a program that can compare a value read from a com-port and one from the terminal. can somebody help me??? using linux kernel 2.6.14-M5 can only use standard function in sh and bash... (5 Replies)
Discussion started by: metal005
5 Replies

3. Shell Programming and Scripting

Error in if condition string comparison

Hello all! I need help in debugging following script. I have no idea where I am going wrong. #!/bin/bash for p1 in A1 TM MP do for p2 in A1 TM MP do for mp1 in N1 N2 do for mp2 in N1 N2 do for mp3 in N1 N2 do for mp4 in N1 N2 do for... (7 Replies)
Discussion started by: RLOA
7 Replies

4. Shell Programming and Scripting

row Comparison

(5 Replies)
Discussion started by: number10
5 Replies

5. Shell Programming and Scripting

$((...)) and $[...] comparison

Does $((mathematical expression)) and $ mean the same? (7 Replies)
Discussion started by: proactiveaditya
7 Replies

6. Solaris

Error in String comparison

Hi, I am getting an error while executing the below code. The error is " then echo "string matches" fi Please help me to solve this error (3 Replies)
Discussion started by: sreedivia
3 Replies

7. Shell Programming and Scripting

need some help..Comparison

I need some help which would probably be for most of you a simple script. I need to read in the data from a .dat file and then compare avg to see who is the highest avg. Here is my script so far. #!/bin/ksh #reading in the data from lab3.dat filename=$1 while read name o1 o2 o3 o4 o5 o6... (0 Replies)
Discussion started by: bluesilo
0 Replies

8. Shell Programming and Scripting

Comparison error

My default shell is ksh. I'm making a simple comparison in a script. ... if then ... i keep getting the error " ] if if if I have also tried all of these with parentheses instead of brackets, nothing works. I know exists1 (I expect it to be 1 in my tests) is being set properly,... (2 Replies)
Discussion started by: lazerfoursix
2 Replies

9. UNIX for Dummies Questions & Answers

Unix comparison

I am very new to Unix. What are the similiarities and differences between ScoUnix and AIX5 if any? Where might i find the information? Which is better? (1 Reply)
Discussion started by: NewGuy100
1 Replies

10. Filesystems, Disks and Memory

comparison

can anyone point me to a comparison of *nix file systems ? i think i prefer a journalling fs but i would like to see a comparison between several fs's before i make up my mind (2 Replies)
Discussion started by: cnf
2 Replies
Login or Register to Ask a Question