
sohnaeo
Novice
May 15, 2007, 12:30 AM
Post #1 of 1
(2497 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
#!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
|