String variable to numeric conversion in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String variable to numeric conversion in perl
# 1  
Old 08-24-2011
String variable to numeric conversion in perl

Hi guys

I am having this strange issue.Well my requirement is like below
Compare two values between flat file and oracle DB

Via perl script I am easily getting the rowcount
Now I connect sql plus via perl and the column value that returns is string

Code:
 
my $sqlplus_settings = ''; 
my $result = qx { sqlplus $connect_string <<EOF 
$sqlplus_settings select (rcrd_cnt) from rptg.r_sb_stg_data_fl_acq_cyc_cntl where data_acq_cyc_cntl_id = (select max(data_acq_cyc_cntl_id) from rptg.r_sb_stg_data_fl_acq_cyc_cntl where srce_id=1 and srce_fl_id = 109 ); 
exit; 
EOF };

But the value returning in $result is string type and can't compare with the flat file row count

Code:
 
its shwoing below error 
"\nSQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 2..." isn't numeric in numeric eq (==) at ./perl5.pl line 52, <FILE> line 13

I also tried
Code:
 
$result = int(chomp($result));

but still no luck

Kindly share your suggestions
# 2  
Old 08-24-2011
Well. Everything is right. You are using the string "\nSQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 2..." in numeric comparison and get this message (with use warnings). And it's not an error, it's a warning.

Why you get it is another question. Debug and tune your request.
# 3  
Old 08-24-2011
Not sure if I understood the issue correctly, but I wonder why you compare the DB reply with the row count instead of the value stored in that row.
# 4  
Old 08-24-2011
Try -s option of sqlplus to suppress any additional information. sqlplus -s
# 5  
Old 08-24-2011
thanks for your reply actually the comparison does not work and I tried to change the string value to numeric value ..can you please let me know how to do the same

Like if the flat file returns 9 and $result also has value 9

By doing comparison with == is not giving exact result
# 6  
Old 08-24-2011
It works (you don't even have to "chomp" the value):
Code:
perl -we 'print "9\n" == 9, "\n"'
1

# 7  
Old 08-24-2011
Hi hfreyer ,

i want to compare the value stored in rcrd_cnt with wc -l of flat file.
at the time of comparing its not giving the exact result throwing string is used warning

---------- Post updated at 08:37 AM ---------- Previous update was at 08:02 AM ----------

To be more specific please find my code and the o/p from unix

Code:
 
my $sqlplus_settings = ''; 
my $result = qx { sqlplus $connect_string <<EOF 
select (rcrd_cnt) from rptg.r_sb_stg_data_fl_acq_cyc_cntl where data_acq_cyc_cntl_id = (select max(data_acq_cyc_cntl_id) from rptg.r_sb_stg_data_fl_acq_cyc_cntl where srce_id=1 and srce_fl_id = 109 ); 
exit; 
EOF };
print "$result \n";
if ( $result == 9)
{
print "\nValues are same\n";
}
else 
{
print "\n values are different \n";
}


Output

Code:
 
SQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 24 08:35:58 2011
Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
    RCRD_CNT
------------
           9
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Argument "\nSQL*Plus: Release 10.2.0.5.0 - Production on Wed Aug 2..." isn't numeric in numeric eq (==) at ./perl4.pl line 12.
 
 values are different

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C++ Get text and numeric value from a string

I have a string opt="row234" I want to put "row" in a string and 234 in an int. In general it should be opt="textnum" I want to store text in a string and num in an int. (6 Replies)
Discussion started by: kristinu
6 Replies

2. Shell Programming and Scripting

PERL : pattern matching a string stored in a variable

I have two variables, my $filename = "abc_yyyy_mm_dd.txt"; my $filename1 = " abc_2011_11_07.txt"; I need to perform some operations after checking if $filename has $filename1 in it i have used the below code, if($filename =~ /^$filename1/) { ---- -- } (2 Replies)
Discussion started by: irudayaraj
2 Replies

3. Shell Programming and Scripting

script for month conversion in numeric format

Hi Experts, How to convert months into numeric format with the help of some script: Suppose I want: " Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sept | Oct | Nov | Dec " to be converted as : " 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 " Thanks in... (2 Replies)
Discussion started by: rveri
2 Replies

4. Shell Programming and Scripting

Replace variable length numeric string

I have a customer who logged some cc and bank account numbers in their apache logs. I got the cc numbers x'd out with sed -e 's/args=\{16\}/args=XXXXXXXXXXXXXXXX/g' -e 's/cardnum=\{16\}/cardnum=XXXXXXXXXXXXXXXX/g'but that wasn't too difficult due to the value being 16 digits. The bank account... (7 Replies)
Discussion started by: mk4mzid
7 Replies

5. Shell Programming and Scripting

Conversion of Exponential to numeric in awk- not correct output

Hi All, I have 1 million records file. Using awk, I am counting the number of records. But as the number is huge, after crossing a number, awk is displaying it in exponential format. At the end, I need to verify this count given by awk with expected count. But as it is in exponential format,... (3 Replies)
Discussion started by: ssunda6
3 Replies

6. Shell Programming and Scripting

:-) 1213: Character to numeric conversion error. Plz help

Dear friends, I am new to Unix/Linux. I am trying to run following query but getting an error msg... Please can u people help me in this? Query: echo "select status_ac from db_acct where acct_num=AAA000337" | dbaccess elstest Error: 217: Column (amd000337) not found in any table in the... (2 Replies)
Discussion started by: anushree.a
2 Replies

7. Shell Programming and Scripting

to check variable if its non numeric

if test $b -ne then echo "\n\n\n\tPassword reset has been done successfully" else echo "\n\n\n\tAn error occurred" fi i want to check whether $b is non-numeric so how to do that? (3 Replies)
Discussion started by: sachin.gangadha
3 Replies

8. Shell Programming and Scripting

perl scalar variable in backquoted string

hi I've been searching all over the internet to simply do the following: $tempfile = "/usr/school/tempfile.dat"; $myvar = param('add'); ###add is the variable assigned to a popup menu `ls -l $myvar * >> $tempfile` ###I also tried `ls -l ${myvar}* >>$tempfile` open(ADDLIST,... (6 Replies)
Discussion started by: mehdi9
6 Replies

9. Shell Programming and Scripting

Perl code to differentiate numeric and non-numeric input

Hi All, Is there any code in Perl which can differentiate between numeric and non-numeric input? (11 Replies)
Discussion started by: Raynon
11 Replies

10. Shell Programming and Scripting

Query string assingment for other variable in PERL

Hi friends, I want to use query string value to another variable but it gives following error when I use it with print out command, Insecure dependency in open while running with -T switch at C:/Program Files/Apache Group/Apache2/cgi-bin/cdr_findere.pl line 119. My code as follows, my... (0 Replies)
Discussion started by: maheshsri
0 Replies
Login or Register to Ask a Question