SELECT table_name FROM user_tables #### SELECT column_name from ALL_CONS_COLUMNS WHERE owner= ? and table_name = ? #### #!/usr/bin/perl -w # utility to generate Docbook tables from # Oracle database # first rev, Oct. 2001 use strict; use DBI; # set up translation table to go from oracle numeric codes # to nice user-readable strings. # yes, DBD::Oracle qw(:ora_types); does the reverse, so I # should probably have used that. Next rev., 'k? my %trans; my @keys = (1..12); my @values = qw(SQL_CHAR SQL_NUMERIC NUMBER SQL_INTEGER SQL_SMALLINT SQL_FLOAT SQL_REAL SQL_DOUBLE DATE SQL_TIME SQL_TIMESTAMP VARCHAR2); @trans{@keys} = @values; $trans{-9112} = "CLOB"; # fields for which to ignore the precision my %no_pres = ( DATE=>1, CLOB=>1 ); #foreach ( sort keys %trans ) { # print "$_ => $trans{$_}\n"; #} # obviously, the next two lines need a-hackin' $ENV{'ORACLE_HOME'} = "/usr/oracle"; my $db = DBI->connect('dbi:Oracle:host="oracle.host.com";sid="SID"', 'username', 'password', {RaiseError=>1, AutoCommit=>0}); my $sth = $db->prepare("SELECT * FROM $table_name") or die "Can't prepare statement: $db->errstr\n"; $sth->execute(); open OUTPUT, ">output.xml" or die "Can't open output.xml for write: $!\n"; select OUTPUT; print < Table Description for $table_name Column Name Column Type END_OF_HEADER my $i = $sth->{NUM_OF_FIELDS}; for my $field ( 0 .. $i-1 ) { print " \n"; print " $sth->{NAME_lc}->[$field]\n"; my $ft = $sth->{TYPE}->[$field]; if ( exists($trans{$ft}) ) { print " $trans{$ft}"; print "($sth->{PRECISION}->[$field])" unless $no_pres{$trans{$ft}}; print "\n"; } else { print "Unknown type $ft\n"; } print " \n"; } print " \n \n\n"; $sth->finish(); close OUTPUT; select STDIN; $db->disconnect; #### perl -e 'print "How sweet does a rose smell? "; chomp ($n = ); $rose = "smells sweet to degree $n"; *other_name = *rose; print "$other_name\n"'