gandolf989 has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a perl script to take SQL stats for queries in my Oracle database and output the results in a formatted way to a scalar,
so that I can send an email. I found this format syntax, but I am not sure if it is still supported or if I am using it correctly.
I just want to make the formatting easy to read, so that I can send it to the developers and they can see the worst SQL running in
the Oracle database. Is there another way that I should write this code? Or do I just need to fix the syntax.
sub print_query_results { my $dbh = shift; my $sql_query = shift; my $sql = SQL::Beautify->new; my ( $sql_id, $min_last_load_time, $buffer_gets, $disk_reads, $exec +utions, $sorts, $parse_calls, $sql_fulltext ); my $return_scalar = qq{ }; my $sth = $dbh->prepare( $sql_query ); $sth->execute(); $sth->bind_columns( undef, \$sql_id, \$min_last_load_time, \$buffer +_gets, \$disk_reads, \$executions, \$sorts, \$parse_calls, \$sql_full +text ); while( $sth->fetch() ) { format OUTPUT = @|||||||||||||||@||||||||||||||||||||@|||||||||||||||@|||||||||||||||@ +|||||||||||||||@|||||||||||||||@||||||||||||||| 'SQL_ID', 'min_last_load_time','buffer_gets', 'disk_reads', ' +executions', 'sorts', 'parse_calls', $sql_id, $min_last_load_time, $buffer_gets, $disk_reads, $ +executions, $sorts, $parse_calls, @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sql->query( $sql_fulltext ) . open OUTPUT, '>', \$return_scalar; write OUTPUT; close OUTPUT; } return $return_scalar; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: I need outputting the results of a query in a formatted way to a scalar, so that I can email the results
by hippo (Bishop) on Sep 20, 2018 at 15:57 UTC | |
by gandolf989 (Scribe) on Sep 20, 2018 at 20:05 UTC | |
by poj (Abbot) on Sep 20, 2018 at 21:12 UTC | |
by gandolf989 (Scribe) on Sep 25, 2018 at 18:42 UTC | |
by hippo (Bishop) on Sep 20, 2018 at 21:15 UTC | |
by BillKSmith (Monsignor) on Sep 20, 2018 at 20:48 UTC |
Back to
Seekers of Perl Wisdom