• notice
  • Congratulations on the launch of the Sought Tech site

Oracle export table structure and comments

Although the DESC command can view the structure of the table, sometimes it is desirable to enter the structure of the table into a table or into EXCEL. Using the DESC command is a bit tedious. In fact, a SQL statement can be.

Query the table structure of the table you can see:

SELECT T1.TABLE_NAME,
       T1.COLUMN_NAME,
       T1.DATA_TYPE || '(' || T1.DATA_LENGTH || ')',
       T2.COMMENTS
  FROM USER_TAB_COLS T1, USER_COL_COMMENTS T2
 WHERE T1.TABLE_NAME = T2.TABLE_NAME
   AND T1.COLUMN_NAME = T2.COLUMN_NAME
   AND T1.TABLE_NAME = 'EMP';

If it is DBA, it is possible to query all table structures through ALL_ and DBA_.

The writing method of SQL92, but I don't know how to add restrictions. It seems that USING can't be used. Of course, you can remove USING and replace it with ON

SELECT TABLE_NAME,
       COLUMN_NAME,
       T1.DATA_TYPE || '(' || T1.DATA_LENGTH || ')',
       T2.COMMENTS
  FROM USER_TAB_COLS T1 INNER JOIN USER_COL_COMMENTS T2
  USING(table_name,COLUMN_name);

Note that if some fields are not commented, they cannot be displayed. Change it like this:
SELECT t.table_name,
       t.colUMN_NAME,
       t.DATA_TYPE || '(' || t.DATA_LENGTH || ')',
       t1.COMMENTS
  FROM User_Tab_Cols t , User_Col_Comments t1
 WHERE t.table_name = t1.table_name
    AND t.column_name = t1.column_name(+);
Just add an outer join.



Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+