smith19 has asked for the wisdom of the Perl Monks concerning the following question:
I am new to perl and i need help in getting output of a sql statements to one variable .can anyone provide me a sample perl code.Below are the sql's i am running and i kept all those sql in one file select instance_name,host_name from v\$instance; select sysdate from dual; select status,destination,dest_id from v\$archive_dest where status ='VALID';
below is the sample code i wrotemy $dbh = DBI->connect ("dbi:Oracle:$v_primary_db","username","passwor +d",{ RaiseError => 1, AutoCommit => 0, ora_session_mode => ORA_SYSDBA + }) || die "Database connection not made: $DBI::errstr"; open (SQL, "$primarysql"); while (my $sqlstatement = <SQL>) { $sth = dbi->prepare($sqlstatement); $sth ->execute(); while (my @row = $sth->fetchrow_array() ){ foreach (@row) { $_="\t" if !defined($_); print "$_\t"; } print "\n"; } } END { $dbh->disconnect if defined($dbh); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiple sql command output to a array variable
by kcott (Archbishop) on Oct 18, 2013 at 06:53 UTC | |
| |
|
Re: multiple sql command output to a array variable
by Anonymous Monk on Oct 18, 2013 at 06:47 UTC |