码迷,mamicode.com
首页 > 数据库 > 详细

ORACLE导出表结构脚本

时间:2016-06-08 01:29:41      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:

select
  case when r = 1 then (select s.COMMENTS from user_tab_comments s where Table_Name= aa.table_name) else ‘‘ end as table_comments,
  case when r = 1 then aa.table_name else ‘‘ end as table_name,
  aa.r as column_sequence,
  aa.COLUMN_NAME,
  aa.DATA_TYPE,
  aa.data_length,
  (select Y
from user_cons_columns cu, user_constraints au
where cu.constraint_name = au.constraint_name and au.constraint_type = P 
  and au.table_name = aa.table_name
  and cu.COLUMN_NAME = aa.COLUMN_NAME) as IS_PK,
  aa.NULLABLE,
  aa.DATA_DEFAULT,
  aa.column_comments
from
(
select  row_number() over(partition by t.OBJECT_NAME order by t.OBJECT_NAME) r,
        t.OBJECT_NAME as table_name,
        c.COLUMN_NAME,
        c.DATA_TYPE,
        case when c.NULLABLE = N then NOT NULL else ‘‘ end as NULLABLE,
        case when c.DATA_TYPE in (NVARCHAR2,CHAR,VARCHAR2) then to_char(c.CHAR_LENGTH)
             when c.DATA_TYPE in (LONG,FLOAT,CLOB,BLOB,DATE)then  
             when c.DATA_TYPE = NUMBER then 
               case when c.DATA_PRECISION is null and c.DATA_SCALE = 0 then
                 INTEGER
                 else
                 rtrim(c.DATA_PRECISION ||,|| c.DATA_SCALE,,)
                 end
             else   end as data_length,
        cc.COMMENTS as column_comments,
        c.DATA_DEFAULT
from user_objects t,
     user_tab_columns  c,
     user_col_comments cc
where t.OBJECT_TYPE = TABLE 
  and c.TABLE_NAME = t.OBJECT_NAME
  and cc.TABLE_NAME = c.TABLE_NAME
  and cc.COLUMN_NAME = c.COLUMN_NAME
) aa;

 

ORACLE导出表结构脚本

标签:

原文地址:http://www.cnblogs.com/kkwoo/p/5568740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!