I am working in Perl from last three months;but using DBI module first time.
While accessing Oracle DB through Perl I got a problem given below.....
when give SQL statement in mysql it is working well ,it is giving all info about that required data e.g if in a table data e.g das has five rows then it is working well and displaying all five required information, but when I passing same statement through perl it is displayin only one information i.e first row.
how to get all five rows?
if anyone can help me
here is my code............
Expand|Select|Wrap|Line Numbers
- #!user/bin/perl
- use strict;
- use DBI;
- use DBD::Oracle;
- my $part_number = $ARGV[0];
- my $dbh = DBI->connect('dbi:Oracle:IDEP', 'cis', 'ci2') || die("Database connection not made: $DBI::errstr");
- my $sql = "SELECT * FROM haz_inactive_table WHERE PART_NBR = '$part_number' ";
- my $sql_count = "SELECT count(*) from haz_inactive_table where PART_NBR='$part_number' ";
- my $sth = $dbh->prepare($sql);
- $sth->execute();
- my @data = $sth->fetchrow_array();
- print"printing @data\n";
- my $sth2 = $dbh->prepare($sql_count);
- $sth2->execute();
- my $count = $sth2->fetchrow_array();
- foreach (@data) {
- $_ = "\t" if !defined($_);
- }
- if($data[0] =~m/$part_number/g) {
- print "Total count exist in database = $count\n";
- print "Part Number exists in database\n";
- print "Printing information about Part Number you entered.........\n";
- print "Part Number = $data[0]\n";
- print "MFR_CODE = $data[1]\n";
- print "PRODUCT_ID = $data[2]\n";
- print "FILE_NAME = $data[3]\n";
- print "flag = $data[4]\n";
- print "TMP_VAL = $data[5]\n";
- print "Maint_Date = $data[6]\n";
- } else {
- print"Either Part Number entered $part_number is invalid \n";
- print"or does not exist in database\n";
- }
- $sth->finish();
- $sth2->finish();
- $dbh->disconnect();