3 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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 <DB-NAME> -u <USER-NAME> -p <PASS-WORD> -f <DESTINATION-PATH> -s <TABLE-SUFFIX>', 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 = <STDIN>) {
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__
3 Einträge, 1 Seite |