Can I get that coloumn names from db???
You can get table and column names from the db using queries:
my (@tables, %map); my $q = $dbh->prepare("show tables"); $q->execute or die "Error listing tables"; while ( my ($table) = $q->fetchrow_array ) { push @tables, $table; } $q->finish; for my $table (@tables) { $q = $dbh->prepare("describe $table"); $q->execute or die "Error describing table $table"; while ( my $hr = $q->fetchrow_hashref ) { push @{ $map{$table} }, $hr->{Field}; } $q->finish; }
Now you have a hash %map keyed on table names, whose values are anonymous arrays containing column names. Use this array to build your query:
my $table_name = "CDR"; my $sql = "select ".join ",", map { "sum($_)" } @{$map{$table_name}}; $sql .= " from $table_name where Date = ? and Hour like ?";
In reply to Re^9: using system command in regex
by shmem
in thread using system command in regex
by ravi45722
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |