Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How to get a db table metadata

by tariqahsan (Beadle)
on Jun 09, 2005 at 16:45 UTC ( #465201=perlquestion: print w/replies, xml ) Need Help??

tariqahsan has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get the column data type and length of a
Oracle database table. Is there a way to do that using DBI?

Replies are listed 'Best First'.
Re: How to get a db table metadata
by cmeyer (Pilgrim) on Jun 09, 2005 at 17:01 UTC
    Take a look at the $dbh->column_info() method of DBI.

    -Colin.

    WHITEPAGES.COM | INC

      Got it done by using $dbh->table_info("", $schema, $table_name, "TABLE");

      Thank you all!

      also be sure too look at methods specific to DBD::Oracle
Re: How to get a db table metadata
by erix (Prior) on Jun 09, 2005 at 16:54 UTC
    select * from cols where table_name = 'YOURTABLE'
Re: How to get a db table metadata
by mifflin (Curate) on Jun 09, 2005 at 17:01 UTC
    You can use the following view...
    SQL>desc all_tab_columns Name Null? Type ------------------------------- -------- ---- OWNER NOT NULL VARCHAR2(30) TABLE_NAME NOT NULL VARCHAR2(30) COLUMN_NAME NOT NULL VARCHAR2(30) DATA_TYPE VARCHAR2(9) DATA_LENGTH NOT NULL NUMBER DATA_PRECISION NUMBER DATA_SCALE NUMBER NULLABLE VARCHAR2(1) COLUMN_ID NOT NULL NUMBER DEFAULT_LENGTH NUMBER DATA_DEFAULT LONG NUM_DISTINCT NUMBER LOW_VALUE RAW(32) HIGH_VALUE RAW(32) DENSITY NUMBER NUM_NULLS NUMBER NUM_BUCKETS NUMBER LAST_ANALYZED DATE SAMPLE_SIZE NUMBER
    Other views would be user_tab_columns and dba_tab_columns (if you have the privs)
    DBI does have some methods (but the perldocs say they are experimental) to extract meta data (at least on the version I'm using it says it's experimental).
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://465201]
Approved by polettix
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2023-09-26 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?