Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: dba_tab_columns
gabsaga_tata_at_hotmail.com (Taji) wrote in
> 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 ) ||
(SELECT MAX(column_id) MAXCOL FROM all_tab_columns WHERE table_name = '%1' AND owner = '%3' ) t2 WHERE t1.table_name = '%1'
-- BillyReceived on Tue Jul 15 2003 - 00:24:29 CDT