This is useful for reproducing a database with an unknown schema into a hash of a hash of an array.
my $sqlstr1 ="select table_name, column_name". " from Dba_tab_columns". " where owner = '$schema'". " order by table_name, column_name"; my $sth=$db->prepare($sqlstr1) or print STDOUT "Query:GetData +Failed"; $sth->execute; my $table_column = $sth->fetchall_arrayref; $sth->finish; for $table_column_r (@{$table_column}) { if ($table_column_r->[0] eq "EMP") { my $sqlstr2 =" select $table_column_r->[1]". " from $schema.$table_column_r->[0]"; my $sth=$db->prepare($sqlstr2) or print STDOUT "Query: +GetTablesColumnsData Failed"; $sth->execute; warn print STDOUT "\n***Error*** Table: $table_column_ +r->[0] Column: $table_column_r->[1] \n", $sth->errstr(), "\n" if $sth->err(); warn print SUMMARY "\n***Error*** Table: $table_column +_r->[0] Column: $table_column_r->[1] \n", $sth->errstr(), "\n" if $sth->err(); my $column_data = $sth->fetchall_arrayref; $sth->finish; # This for-loop create a hash of a hash of an array wi +th the keys {table name} and {column name} for $row (@{$column_data}) { push (@{$tables{$table_column_r->[0]}{$table_colum +n_r->[1]}}, $row->[0]); # To print value of hash: p @{$tables{$table_colum +n_r->[0]}{$table_column_r->[1]}} } undef @data_array; } }

In reply to Database Table to Hash of Hash of Array by timo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.