--以表AA11为例

select 'create table ' || a.table_name || '(' || chr(10) ||

       (select TO_CHAR(wm_concat(b.column_name || ' ' || b.DATA_TYPE || '(' ||
                                 b.DATA_LENGTH || ') ' ||
                                 decode(b.NULLABLE, 'N', ' not null ', '') ||
                                 chr(10)))
          from (select * from user_tab_columns order by COLUMN_ID) b
         where b.table_name = a.table_name) || ');' || chr(10) ||
       'comment on table ' || a.table_name || ' is ''' || comments||''';'||chr(10)||
       (select replace(TO_CHAR(wm_concat('comment on column '||e.table_name||'.'||e.column_name||' is '''||e.comments||''';')),',',chr(10)) from (select c.TABLE_NAME,c.COLUMN_NAME,d.comments from user_tab_columns c,user_col_comments d where c.table_name=d.table_name and c.column_name=d.column_name order by c.COLUMN_ID) e where e.table_name=a.table_name) 
  from user_tab_comments a

 WHERE A.table_name = 'AA11';

--结果如下

根据数据库中已存在的表,反向生成建表脚本

相关文章:

  • 2022-12-23
  • 2022-01-09
  • 2022-01-07
  • 2021-12-22
  • 2021-05-21
  • 2021-12-07
  • 2021-12-25
  • 2021-04-17
猜你喜欢
  • 2022-02-18
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-11-20
相关资源
相似解决方案