#!/usr/bin/perl -w
#
# mindlessly pull WHERE clauses from PL/SQL, using a first approximation
# to the dumbest method possible, and send an ordered list of those found
# to STDOUT, with a preceding count that tells you how often each one occurs.
#
# HTH. HAND.
#
# scribbled down by frank@limov.com between package re-compiles
#

my %all=();
my $where='';

LINE:
while (<>) {
  next LINE unless /\bWHERE\b/;   # by convention, we only SHOUT in SQL
  $where='';

  do {
    $where.=$_;
    if (/;/) {			  # what, you were expecting a parser maybe?
      ++$all{$where};
      next LINE;
    }
  } while(<>);
}

foreach $where (reverse sort { $all{$a} <=> $all{$b} } keys %all) {
  print $all{$where},": ", $where, "\n";
}
