How to select the rows from oracle table using perl?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to select the rows from oracle table using perl?
# 1  
Old 02-04-2011
How to select the rows from oracle table using perl?

Hi,

I am connecting to oracle database using perl.

I am able to connect but i am not able to get all the rows from the table.

Here is the code.

Code:
#!/usr/bin/perl
use DBI;
my $dbh=DBI->connect("DBI:Oracle:student","class","welcome") or die "Couldnot connect oracle Database";
$sth=$dbh->prepare("select * from dummy")or die "cannot prepare the selected statement";
$sth->execute() or die "cannot execute the statement";
print "entered\n";
my @row;
while (@row = $sth->fetchrow_array) {  # retrieve one row
    print join(", ", @row), "\n";
}

Here is the table structure in Oracle.

Code:
SQL> describe dummy;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 NAME                                               VARCHAR2(10)

SQL> select * from dummy;

NAME
----------
aaa
eee

I am not able to get the output. The output should be:

Code:
aaa eee

How can i get the above output in perl?

Help is very much appreciated.

Regards
# 2  
Old 02-04-2011
Quote:
Originally Posted by vanitham
...
I am not able to get the output. The output should be:
Code:
aaa eee

How can i get the above output in perl?
...
Code:
C:\>
C:\>type fetch.pl
#!perl -w
use strict;
use DBI;
my $dbh;
my $sth;
my $name;
my $namelist;
$dbh = DBI->connect("DBI:Oracle:student","class","welcome") or die $dbh->errstr;
$sth = $dbh->prepare("select name from dummy") or die $dbh->errstr;
$sth->execute() or die $dbh->errstr;
while ($name = $sth->fetchrow) {
$namelist .= " $name";
}
print $namelist;
$sth->finish();
$dbh->disconnect();
 
C:\>
C:\>perl fetch.pl
 aaa eee
C:\>
C:\>

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Average select rows

I have no idea how to even get started with this script. I need to average field 3 for each of the unique identifiers found in field 1. However, I only want to average these rows when field 2 is equal to 1506 - 2000 (note that i replaced the values field 2 for security reasons, but the real... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

2. UNIX and Linux Applications

Help in copying table structure to another table with constraints in Oracle

hi, i need to copy one table with data into another table, right now am using create table table1 as select * from table2 i want the constraints of table1 to be copied to table2 also , can anyone give me some solution to copy the constraints also, now am using oracle 10.2.0.3.0... (1 Reply)
Discussion started by: senkerth
1 Replies

3. Shell Programming and Scripting

Select table name from file

i have a file tabel.out which contain table name in this format. xyz abc qwe Plz help me writing one script which actually takes tablename from file table.out file one by one and then select count (*) from $tablename limit 10; and print error in output file if any tabel is not... (4 Replies)
Discussion started by: netdbaind
4 Replies

4. Shell Programming and Scripting

Select rows where the 3rd column value is over xx

Hi All, I've got a text file which is Postcode,Postcode, Travel_time and I want to select all of the rows where the 3rd column value is over 255. Can someone show me the magic on how to do this? Originally it did contain 4 columns but i've managed to strip out the first 3 using: cat textfile |... (3 Replies)
Discussion started by: gman
3 Replies

5. Shell Programming and Scripting

select values from db1 table and insert into table of DB2

Hi I am having three oracle databases running in three different machine. their ip address is different. from one of the DB am able to access both the databases.(means am able to select values and insert values in to tables individually.) I need to fetch some data from DB1 table(say DB1 ip is... (2 Replies)
Discussion started by: aemunathan
2 Replies

6. Shell Programming and Scripting

select data from oracle table and save the output as csv file

Hi I need to execute a select statement in a solaris environment with oracle database. The select statement returns number of rows of data. I need the data to be inserted into a CSV file with proper format. For that we normally use "You have to select all your columns as one big string,... (2 Replies)
Discussion started by: rdhanek
2 Replies

7. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time then Go to sleep mode and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

8. Shell Programming and Scripting

Check the record count in table (table in oracle)

I have requirement: 1) Check the record count in table (table in oracle) 2) If records exists generate the file for existing records and wait for some time (Go to sleep mode) and Again check the record count after 10 min.......... (Loop this process if record count >0). 3) Generate touch... (1 Reply)
Discussion started by: kamineni
1 Replies

9. HP-UX

to create a oracle table in perl script

Hi all, I have to create table for each month inside a perl script. tablename_monthnameyear. megh_aug2008 for august 2008. megh_sep2008 for september 2008. just like the logfiles created on date basis. thanks megh (1 Reply)
Discussion started by: megh
1 Replies
Login or Register to Ask a Question