Hello,
I was wondering if you ever got an answer to your question?
If not, I may have a solution for you. I was trying to
resolve the very same issue a couple of years ago and
wrote this quick script as a test to see if it could
be done using the 'table_info()' method provided by
the DBI module.
Here is the script:
<Start>
#! /usr/bin/perl
use DBI;
#
# Create the database handle. Be sure to replace everything
# between the '<>' (not including them) with the values which
# are specific to your system.
#
$DBHandle = DBI->connect(
"dbi:Oracle:host=<HostName>;sid=<DBName>",
"<UserID>",
"<Password>"
);
#
# Fill-in all or part of your table schema name here.
# If you use the entire name, you may remove the wildcard (%).
#
%Attributes = (
TABLE_SCHEM => "<SchemaID>%",
);
#
# Define the statement handle to get the table metadata.
#
$SQLStatement = $DBHandle->table_info(\%Attributes);
#
# This part is not really necessary. It just allows
# for an orderly display of the output in tabular
# format.
#
open(HEADER);
$~ = "HEADER";
write();
select(STDOUT);
close(HEADER);
open(TABLE_INFO);
$~ = "TABLE_INFO";
while (($Catalog, $Owner, $TableName, $Type, $Remarks) = $SQLStatement->fetchrow_array())
{
foreach ($Catalog, $Owner, $TableName, $Type, $Remarks)
{
$_ = "N/A" unless defined($_);
}
write();
}
select(STDOUT);
close(TABLE_INFO);
#
# Define the header and body formats for the output.
#
format HEADER =
Catalog Owner Table Name Type
---------- ----------- ---------------------------- --------------------
..
format TABLE_INFO =
@<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<
$Catalog, $Owner, $TableName, $Type
..
</End>
There are other values availble to you via 'table_info()', only
a few of which are displayed in the table above.
Once I got this issue answered, I was able to quickly
code something more specific to the work I was doing
at the time.
If you have other questions, let me know.
Marcus E. Harris
Aug 1, ngoc said:
n| Hi
n| I use "my $header_sql = qq { desc $table };". It does not work.
n| But "select column_name from all_tab_columns where table_name = \'$table\'"
n| work.
n| My problem is "desc $table" matching which "select * from $table"
n| than
n| select column_name ...........
n| (I mean data and column name order matching).
n| Thanks
n|
--
..:::::::::::::::::::::::::::: Signature :::::::::::::::::::::::::::::::::.
.. .
.. Marcus E. Harris [Engineer] | Work Phone: 919.463.3162 .
.. Lucent Technologies | FAX: 919.463.4479 .
.. 200 Lucent Lane | E-Mail: (e-mail address removed) .
.. Room #SE405G | Conf. Bridge: 800.450.3848, x322703 .
.. Cary, North Carolina 27511 | Lucent IM: (e-mail address removed) .
.. .
.. .
.. "If you can't be a good example, then you'll just have to be a .
.. horrible warning..." -- Catherine Aird .
.. .
..:::::::::::::::::::::::::::: Signature :::::::::::::::::::::::::::::::::.