# "RaiseError => 1" tells DBI to die on errors. my $dbh = DBI->connect($DSN, $username, $password, { RaiseError => 1 }); my $sth; $sth = $dbh->prepare(" SELECT table_name, column_name FROM Dba_tab_columns WHERE owner = ? ORDER BY table_name, column_name "); $sth->execute($schema); my $table_column = $sth->fetchall_arrayref; $sth->finish; for my $tcr (@{$table_column}) { if ($tcr->[0] eq "EMP") { my $sth = $dbh->prepare("SELECT " . $tcr->[1] . " FROM " . $schema . $tcr->[0]); $sth->execute; my $column_data = $sth->fetchall_arrayref; $sth->finish; # This for-loop create a hash of a hash of an array with the keys {table name} and {column name} for my $row (@{$column_data}) { push @{ $tables{$tcr->[0]}{$tcr->[1]} }, $row->[0]; } } }