#! /usr/bin/perl -w use strict; use DBI; use constant DBI_AGR => 'dbi:Oracle:agrtest'; my $table = shift; my $dbo = DBI->connect( DBI_AGR, 'foo', 'bar', {PrintError => 1} ) or die "Couldn't connect to @{[DBI_AGR]}\n"; #foreach( $dbo->tables ) { # print "$_\n"; #} #print "\n"; my $typeinfo = $dbo->type_info_all;; my $tnames = shift @$typeinfo; my %typenames; foreach( %$tnames ) { $typenames{$tnames->{$_}} = $_; # print "$_ => $tnames->{$_}\n"; } if( !defined $table ) { print join( "\t" => @typenames{sort {$a<=>$b} keys %typenames} ), "\n"; my $nr = 0; foreach my $ti( @$typeinfo ) { print $nr++; foreach my $t( @$ti ) { print "\t", $t ? $t : 'undef'; } print "\n"; } } my $sth = $dbo->table_info; while( my $d = $sth->fetchrow_hashref ) { if( defined $table ) { next unless uc $table eq uc $d->{TABLE_NAME}; } print "$d->{TABLE_NAME}\t$d->{TABLE_TYPE}\n"; my $sdump = $dbo->prepare( "select * from $d->{TABLE_NAME}" ); if( $sdump->execute ) { my $names = $sdump->{NAME}; my $types = $sdump->{TYPE}; my $nr = $sdump->{NUM_OF_FIELDS}; for( my $n = 0; $n < $nr; ++$n ) { print "\t$n\t$names->[$n]\t$types->[$n]\n"; } } $sdump->finish; print "\n"; }