dbTalk Databases Forums  

Re: dba_tab_columns

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Re: dba_tab_columns in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Billy Verreynne
 
Posts: n/a

Default Re: dba_tab_columns - 07-15-2003 , 12:24 AM






gabsaga_tata (AT) hotmail (DOT) com (Taji) wrote in

Quote:
Does anyone happen to know the exact select statement that the
'describe' command emulates? I tried something like the following but
it didn't exactly work 'cause when the data_type is a VARCHAR, it
doesn't show the number of characters.
Try something like the following. %3 is the owner and %1 is the
tablename. This does not do partition, iot's and is also missing
constraints, support for more exotic data types and so on. But it does
the vanilla basics.

You may want to change the chr(13) into a proper linefeed too.

CREATE TABLE %3.%1 ' "LINE"
FROM dual
UNION ALL
SELECT
'('
FROM dual
UNION ALL
SELECT
*
FROM (
SELECT
' ' || RPAD( LOWER(t1.column_name), 30 ) ||
RPAD(
DECODE( t1.data_type,
'DATE', t1.data_type,
'NUMBER', t1.data_type ||'(' || t1.data_precision ||
DECODE( t1.data_scale,0, ')', ',' || t1.data_scale || ')' ) ,
t1.data_type ||'(' || t1.data_length || ')'
) , 20 ) ||
DECODE( t1.nullable, 'Y', '',
'NOT NULL') ||
DECODE( t2.maxcol, NULL, ',' , '' ) "COLUMN"
FROM all_tab_columns t1,
(SELECT MAX(column_id) MAXCOL FROM all_tab_columns
WHERE table_name = '%1'
AND owner = '%3' ) t2
WHERE t1.table_name = '%1'
AND t1.owner = '%3'
AND t1.column_id = t2.maxcol (+)
ORDER BY t1.column_id )
UNION ALL
SELECT
')'
FROM dual
UNION ALL
SELECT
'TABLESPACE ' || lower(a.tablespace_name)
FROM all_tables a
WHERE a.table_name = '%1'
AND a.owner = '%3'
UNION ALL
SELECT
DECODE( a.logging, 'YES', 'LOGGING', 'NOLOGGING' ) || chr(13) ||
'PCTFREE ' || a.pct_free || chr(13) ||
'PCTUSED ' || a.pct_used || chr(13) ||
'INITRANS ' || a.ini_trans || chr(13) ||
'MAXTRANS ' || a.max_trans || chr(13) ||
'PARALLEL ( degree ' || LTRIM(a.degree) || ' instances ' ||
LTRIM(a.instances) || ' )' || chr(13) ||
'STORAGE(' || chr(13) ||
' initial ' || a.initial_extent || chr(13) ||
' next ' || a.initial_extent || chr(13) ||
' minextents ' || a.min_extents || chr(13) ||
' maxextents ' || a.max_extents || chr(13) ||
' pctincrease ' || a.pct_increase || chr(13) ||
' freelists ' || a.freelists || chr(13) ||
' buffer_pool ' || a.buffer_pool || chr(13) ||
' freelist groups ' || a.freelist_groups || chr(13) ||
' )'
FROM all_tables a
WHERE a.table_name = '%1'
AND a.owner = '%3'


--
Billy


Reply With Quote
  #2  
Old   
Taji
 
Posts: n/a

Default Re: dba_tab_columns - 07-15-2003 , 01:59 PM






Well, finally got it work and if anyone was wondering, here is the
code.

select column_name,
decode (nullable, 'Y', 'NULL','NOT NULL') as "Null?",
RTRIM(decode(data_type || '(' || data_precision ||
decode(data_scale,0,'',null,'',',' || data_scale) || ')',
'DATE()','DATE',
'VARCHAR2()', data_type || '(' || data_length || ')' ,
data_type || '(' || data_precision ||
decode(data_scale,0,'',null,'',',' || data_scale) || ')')) as type
from dba_tab_columns where table_name = 'TABLE_NAME_GOES_HERE' order
by column_id


Taji


Sybrand Bakker <gooiditweg (AT) sybrandb (DOT) demon.nl> wrote

Quote:
On 14 Jul 2003 14:17:16 -0700, gabsaga_tata (AT) hotmail (DOT) com (Taji) wrote:

Does anyone happen to know the exact select statement that the
'describe' command emulates? I tried something like the following but
it didn't exactly work 'cause when the data_type is a VARCHAR, it
doesn't show the number of characters.

select column_name, decode (nullable, 'Y', 'NULL','NOT NULL') ,
data_type,
data_precision,
data_scale
from dba_tab_columns
where table_name = 'TABLE_NAME_GOES_HERE' order by column_id"

Thanks.

Taji.


I don't think your assertion is correct. IIRC there is a data_length
column which is being used in non-numeric columns
Just describe dba_tab_columns, grin


Sybrand Bakker, Senior Oracle DBA

To reply remove -verwijderdit from my e-mail address

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.