注意的地方:拼接的sql可能超出了要截取的长度,字符串varchar2最多存储4000
select to_char(substr(table_prefix || col_strs || table_subfix, 1, 4000)) con
from (select n.table_prefix,
wm_concat(m.col_str) as col_strs,
n.table_subfix
from (select a.table_name,
'drop table if exists ' || lower(a.table_name) ||
';create table ' || lower(a.table_name) || '(' as table_prefix,
') comment ''' || b.comments ||
''' ROW FORMAT DELIMITED FIELDS TERMINATED BY ''\t'' ESCAPED BY ''\\'' STORED AS TEXTFILE;' as table_subfix
from user_tables a, user_tab_comments b
where a.table_name = b.table_name
--and a.table_name = 'MID'
order by a.table_name) n,
(select c.TABLE_NAME,
c.column_name || ' ' ||
decode(c.data_type,
'VARCHAR2',
'varchar' || '(' || c.DATA_LENGTH || ')',
'NUMBER',
'int',
'DATE',
'timestamp',
'CHAR',
'CHAR' || '(' || c.DATA_LENGTH || ')',
'CLOB',
'