Last active
December 14, 2015 13:59
-
-
Save henices/5097678 to your computer and use it in GitHub Desktop.
Extract SQL from an Oracle SQL Trace File (10046)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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