Skip to content

Instantly share code, notes, and snippets.

@henices
Last active December 14, 2015 13:59
Show Gist options
  • Save henices/5097678 to your computer and use it in GitHub Desktop.
Save henices/5097678 to your computer and use it in GitHub Desktop.
Extract SQL from an Oracle SQL Trace File (10046)
#!/usr/bin/perl
# David Mann
# ba6.us
# Extract SQL from an Oracle SQL Trace File (10046)
#
# Usage:
# Data is read from STDIN
# trc2sql.pl output.sql
#
# Change log:
# 13-OCT-2011 : Release
# 6-Mar-2013 : Support bind var, add by @henices
$InSQL = 0;
$InBIND = 0;
while (<>) {
$MyLine = $_;
$LineNum = $LineNum + 1;
if ($MyLine =~ /====/) {
print "$MyLine\n";
}
# If END OF STMT found, stop printing
if (($InSQL==1) && ($MyLine =~ /END OF STMT/ )) {
print ";\n\n\n";
$InSQL = 0;
}
if (($InBIND==1) && ($MyLine =~ /value/ )) {
print $MyLine;
}
if (($InBIND==1) && ($MyLine =~ /EXEC/ )) {
print ";\n\n\n";
$InSQL = 0;
}
# In matching pattern, continue printing
if ($InSQL == 1) {
print $MyLine;
}
# If PARSING IN CURSOR found, start printing
if ($MyLine =~ /PARSING IN CURSOR/) {
print "-- " . $MyLine;
$InSQL = 1;
}
if ($MyLine =~ /BINDS #/) {
print "-- " . $MyLine;
$InBIND = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment