473,240 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,240 software developers and data experts.

DBI Problem

3
Hi all
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
  1. #!user/bin/perl
  2. use strict;
  3. use DBI;
  4. use DBD::Oracle;
  5.  
  6. my $part_number = $ARGV[0];
  7. my $dbh = DBI->connect('dbi:Oracle:IDEP', 'cis', 'ci2') || die("Database connection not made: $DBI::errstr");
  8.  
  9. my $sql = "SELECT * FROM haz_inactive_table WHERE PART_NBR = '$part_number' ";
  10. my $sql_count = "SELECT count(*) from haz_inactive_table where PART_NBR='$part_number' ";
  11.  
  12. my $sth = $dbh->prepare($sql);
  13. $sth->execute();
  14. my @data = $sth->fetchrow_array();
  15. print"printing @data\n";
  16.  
  17. my $sth2 = $dbh->prepare($sql_count);
  18. $sth2->execute();
  19. my $count = $sth2->fetchrow_array();
  20.  
  21. foreach (@data) {
  22.     $_ = "\t" if !defined($_);
  23. }
  24.  
  25. if($data[0] =~m/$part_number/g) {
  26.     print "Total count exist in database = $count\n";
  27.     print "Part Number exists in database\n";
  28.     print "Printing information about Part Number you entered.........\n";
  29.     print "Part Number = $data[0]\n";
  30.     print "MFR_CODE = $data[1]\n";
  31.     print "PRODUCT_ID = $data[2]\n";
  32.     print "FILE_NAME = $data[3]\n";
  33.     print "flag = $data[4]\n";
  34.     print "TMP_VAL = $data[5]\n";
  35.     print "Maint_Date = $data[6]\n";
  36. } else {
  37.     print"Either Part Number entered $part_number is invalid \n";
  38.     print"or does not exist in database\n";
  39. }
  40.  
  41. $sth->finish();
  42. $sth2->finish();
  43. $dbh->disconnect();
  44.  
Feb 27 '07 #1
3 1981
KevinADC
4,059 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. while(my @data = $sth->fetchrow_array()) {
  2.    print"printing @data\n";
  3.    .....
  4. }
Feb 27 '07 #2
das
3
hi all
I got the ans
not need to waste ur time
Feb 28 '07 #3
miller
1,089 Expert 1GB
hi all
I got the ans
not need to waste ur time
Call it wasted effort, but I felt like cleaning up your code a little bit anyway. There's still a lot of wierd and probably useless logic in it that I predict was used for debugging purposes, but this is more or less what you were aiming for:

Expand|Select|Wrap|Line Numbers
  1. #!user/bin/perl
  2. use strict;
  3. use DBI;
  4. use DBD::Oracle;
  5.  
  6. my $part_number = $ARGV[0];
  7.  
  8. my $dbh = DBI->connect('dbi:Oracle:IDEP', 'cis', 'ci2') or die("Database connection not made: $DBI::errstr");
  9.  
  10. my $sql_count = "SELECT count(*) from haz_inactive_table where PART_NBR='$part_number' ";
  11. my $sth = $dbh->prepare($sql_count);
  12. $sth->execute() or die $dbh->errstr;
  13. my $count = $sth->fetchrow_array();
  14. $sth->finish();
  15.  
  16. my $sql = "SELECT * FROM haz_inactive_table WHERE PART_NBR = '$part_number' ";
  17. my $sth = $dbh->prepare($sql);
  18. $sth->execute() or die $dbh->errstr;
  19.  
  20. while (my @data = $sth->fetchrow_array()) {
  21.     print"printing @data\n";
  22.  
  23.     foreach (@data) {
  24.         $_ = "\t" if !defined($_);
  25.     }
  26.  
  27.     if($data[0] =~m/$part_number/g) {
  28.         print "Total count exist in database = $count\n";
  29.         print "Part Number exists in database\n";
  30.         print "Printing information about Part Number you entered.........\n";
  31.         print "Part Number = $data[0]\n";
  32.         print "MFR_CODE = $data[1]\n";
  33.         print "PRODUCT_ID = $data[2]\n";
  34.         print "FILE_NAME = $data[3]\n";
  35.         print "flag = $data[4]\n";
  36.         print "TMP_VAL = $data[5]\n";
  37.         print "Maint_Date = $data[6]\n";
  38.     } else {
  39.         print"Either Part Number entered $part_number is invalid \n";
  40.         print"or does not exist in database\n";
  41.     }
  42. }
  43.  
  44. $sth->finish();
  45. $dbh->disconnect();
  46.  
It's the stuff inside the while loop that you probably could cut.

- M
Mar 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.