CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: DBI:
DBI Oracle script

 



sohnaeo
Novice

May 15, 2007, 12:30 AM

Post #1 of 1 (3029 views)
DBI Oracle script Can't Post

Hi Guys,

I have DBI oracle script that fetches data from more than one table, output is coming into columns, how i can display these in row rather than in column.

if u look at the code, sql query is in the loop, query returns more than one item for every element, I need commas between items for one element and then new line for different elements. i dont know it is possible or not

code is attached


Code
#!F:/perl/bin/perl.exe 

use DBI;


open(FH,"C:/ehealth/custom/Script/test");

foreach $fin (<FH>) {

my($final) = split(/\n/,$fin);

my $dbh = DBI->connect( 'dbi:Oracle:xxxxxxx','xxxxxx','xxxxxx',{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::er
+rstr";


my $sql = qq(select c.name from NH_Element a, nh_group_members b, nh_g
+roup c where a.element_id = b.element_id and b.group_id = c.group_id
+and a.name='$final' ORDER by c.name);

my $sth = $dbh->prepare( $sql );

$sth->execute();

my($alias);

$sth->bind_columns( undef,\$alias);

while($sth->fetchrow_array()) {

print "$alias\n";

}

$sth->finish();

$dbh->disconnect();


}
close(FH);


test File is as

S60172C151887-RH
mgr01.beg01-RH

sql query returns folliwng for S60172C151887-RH

CMS-Monitoring
CUST-RCE

and folliwng for mgr01.beg01-RH

WoG_Routers
gnet-all

but my script returns all as, can't differentiate between output

CMS-Monitoring
CUST-RCE
WoG_Routers
gnet-all



Wanting Output as:

CMS-Monitoring,CUST-RCE
WoG_Routers,gnet-all

Thanks,

Farhan

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives