# Program to get the Query, Parse count, Execute count, Fetch count, Total cpu time and Total elapsed time.
# Begin Prompt for User Input .. Input Trace File
$inputFile = &promptUser("\n\t\t Enter the TraceFile Name");
#Open input and output files and create File Handles
open(INFILE,"<$inputFile") or die " Input File opening ERROR :: $!";
$opFile = $inputFile.".xls";
open(OUTFILE,">$opFile") or die " Output File opening ERROR :: $!";
# Write the Headings to the file
print OUTFILE "SQL Query and the Indexes used in the Query is printed in the output_log file \n\n";
#print OUTFILE "===================================================================\n";
#print OUTFILE "SQL QUERY ~PARSE Count ~EXECUTE Count ~FETCH Count ~TOTAL CPU TIME ~TOTAL ELAPSED TIME ~FullTableScan\n";
# initializations
$SQLLINE="";
$CUTLINE="";
$CUTLINE1="";
$FLAG=0;
$SUFLAG=0;
$Indexflag=0;
$MyFlag=0;
$Rows=0;
$Blocks=0;
$Result=0;
$Zero=0;
$Level=10;
#
# Working on the input file One Line at a Time !!! Read from given I/P file Line by Line.
foreach $actual_line (<INFILE>)
{
# To get the PLAN !!!
\# if line is a sql statement change the flag status
\# and copy the line to a variable
if\( $actual_line =~ m/^SELECT/ || $actual_line =~ m/^select/ || $actual_line =~ m/^update/ || $actual_line =~ m/^UPDATE/\) \{
$FLAG=1;
$SUFLAG=1;
\#print OUTFILE "------------------------------------------------------------------------------- \\n\\n";
chomp\($actual_line\);
$SQLLINE=$actual_line;
\}
\#change the flag status when complete sql statement is read
elsif\($actual_line =~ m/^call/\)\{
\#print "call";
$FLAG=0;
print OUTFILE "***************************************************************************** \\n";
print OUTFILE "$SQLLINE" ;
$CUTLINE=$SQLLINE;
@charArray = split\(/FROM/,$CUTLINE\);
$CUTLINE1=@charArray[1];
print OUTFILE "$CUTLINE1" ;
$SQLLINE="";
next;
\}
\# read the complete sql statement line by line and join them together
elsif\($FLAG==1\) \{
chomp\($actual_line\);
$line=$actual_line;
$temp=$SQLLINE;
$SQLLINE=$temp.$line;
next;
\}
\# Above code Completes the program for copying the SQL Query.
else\{
next;
\}
}
##
# Close all file handles !!!
##
close(INFILE) or die " INFILE CLOSING ERROR : $!";
close(OUTFILE) or die " OUTFILE CLOSING ERROR : $!";
#
# Display Console message to user ..
print "\t\tOUTPUT printed to File : $opFile \n";
# Prompting the usr to enter an Input file or accept a default I/P File ...
#
#
sub promptUser
{
local\($promptString,$defaultValue\) = @_;
if \($defaultValue\)
\{
print $promptString, "[", $defaultValue, "]: ";
\}
else
\{
print $promptString, ": ";
\}
$| = 1; \# force a flush after our print
$_ = <STDIN>; \# get the input from STDIN \(presumably the keyboard\)
chomp;
if \("$defaultValue"\)
\{
return $_ ? $_ : $defaultValue; \# return $_ if it has a value
\}
else
\{
return $_;
\}
}
This is the code that I have created. The problem comes as it is splitting for FROM but it is not splitting for from.
Also need to continue with the logic