use strict; use Data::Dumper; use Getopt::Std; use DBI; use constant ENDL => "\n"; use constant DELIMITER => "/"; use constant SEPARATOR => " "; use constant EXTENSION => ".txt"; our %opts; getopts('d:u:p:f:s:', \%opts); if(!exists($opts{d}) || !exists($opts{u}) || !exists($opts{p}) || !exists($opts{f}) || !exists($opts{s})) { print 'USAGE: -d -u -p -f -s ', ENDL; exit(-1); } my($db, $usr, $pwd); $db = 'DBI:Oracle:' . $opts{d}; $usr = $opts{u}; $pwd = $opts{p}; my $dbh = DBI->connect($db, $usr, $pwd) or die $DBI::errstr; while(my $sql_queries = ) { chomp($sql_queries); chop($sql_queries); my $query = undef; my @line_rows = split(/ /, $sql_queries); open(SQL, '>', $opts{f} . DELIMITER . uc($opts{s}) . SEPARATOR . $line_rows[2] . EXTENSION) or die $!; print SQL uc($opts{s} . SEPARATOR . $line_rows[2]), ENDL, ENDL; $query = 'select count(' . $line_rows[2] . ') from ' . uc($opts{s}); print SQL $query, ENDL; $query = $dbh->prepare($query); $query->execute(); print SQL $query->fetchall_arrayref->[0][0], ENDL, ENDL; $query = 'select count(distinct ' . $line_rows[2] . ') from ' . uc($opts{s}); print SQL $query, ENDL; $query = $dbh->prepare($query); $query->execute(); print SQL $query->fetchall_arrayref->[0][0], ENDL, ENDL; $query = 'select min(' . $line_rows[2] . ') from ' . uc($opts{s}); print SQL $query, ENDL; $query = $dbh->prepare($query); $query->execute(); print SQL $query->fetchall_arrayref->[0][0], ENDL, ENDL; $query = 'select max(' . $line_rows[2] . ') from ' . uc($opts{s}); print SQL $query, ENDL; $query = $dbh->prepare($query); $query->execute(); print SQL $query->fetchall_arrayref->[0][0], ENDL, ENDL; $query = 'select distinct ' . $line_rows[2] . ' from ' . uc($opts{s}); print SQL $query, ENDL; $query = $dbh->prepare($query); $query->execute(); print SQL $query->fetchall_arrayref->[0][0], ENDL, ENDL; close(SQL) or die $!; } $dbh->disconnect or die $dbh->errstr; __END__