Andy Duncan wrote:
> > Can someone please instruct me as to how I can output a DESCRIBEd value of a
> > table in DBI?
>
> DESCRIBE is a command written especially for SQL*Plus, and is not a standard
> SQL command.
Actually, DESCRIBE is a standard part of SQL-92, for use with Dynamic SQL in
Embedded SQL.
> To get something similar to DESCRIBE in raw SQL, you'll have to
> write some code which accesses the Oracle data dictionary (which is all the
> DESCRIBE program does itself, probably). The following primitive code might
> get you started, though it only covers "real" tables. To get something to
> cover synonyms and views, you might want to modify and wrap this within some
> PL/SQL using DBMS_OUTPUT and add some other stuff to get other objects other
> than straight tables:
>
> select COLUMN_NAME "Name"
> ,DECODE(NULLABLE,'Y','','N','NOT NULL') "Null"
> ,SUBSTR(DECODE(DATA_TYPE,'CHAR',
> 'CHAR('||TO_CHAR(DATA_LENGTH)||')'
> ,'VARCHAR2','VARCHAR2('||
> TO_CHAR(DATA_LENGTH)||')'
> ,'NUMBER','NUMBER('||
> TO_CHAR(DATA_PRECISION)||
> ','||TO_CHAR(DATA_SCALE)||')'
> ,DATA_TYPE),1,30) "Type"
> from user_tab_columns
> where table_name = 'MY_TABLE'
> order by COLUMN_ID
> /
>
> Once you've wrapped this within some PL/SQL (or created some views?), you'll
> then be able to do something in SQL*Plus like:
>
> execute my_desc('MY_TABLE');
>
> Within DBI, use the special 'func' methods available within DBD::Oracle
> (documented within the DBD::Oracle distribution), to get the output too.
With DBI, there are standard attributes that contain information from DESCRIBE
(not all in one call, but most of it is available); with DBD::Informix, there are
non-standard attributes that contain the native Informix version of the
information from DESCRIBE.
Time to break out the Cheetah book -- TYPE, NULLABLE, NAME, etc.
--
Jonathan Leffler ([EMAIL PROTECTED], [EMAIL PROTECTED])
Guardian of DBD::Informix 1.00.PC1 -- see http://www.cpan.org/
#include <disclaimer.h>