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;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.