您的位置:首页 > 数据库 > Oracle

获取oracle表的元素据,拼凑hive建表语句以及需要的conf

2017-01-08 16:00 375 查看
1.获取建表语句:

select t.OWNER,t.COLUMN_ID,t.COLUMN_NAME,' ', 'STRING',' ',concat(concat('COMMENT" ',t2.COMMENTS),'",') as commentname
from all_tab_columns t
left join all_tab_comments t1
on t.OWNER=t1.OWNER
and t.TABLE_NAME=t1.TABLE_NAME
left join all_col_comments t2
on t.OWNER=t2.OWNER
and t.TABLE_NAME=t2.TABLE_NAME
and t.COLUMN_NAME=t2.COLUMN_NAME
where t.TABLE_NAME='表名'
order by t.OWNER,t.TABLE_NAME,COLUMN_ID;


2.获取字段中间用逗号隔开

select wm_concat(COLUMN_NAME) from (
select t.COLUMN_NAME from all_tab_columns t where t.TABLE_NAME='表名'
and t.OWNER='属主'order by t.OWNER,t.TABLE_NAME,COLUMN_ID)


3.查询表的大小(根据表大小判断是否增量或者全量迁移数据1G一下全量,1G以上增量)

Select Segment_Name, to_char( Sum(bytes) / 1024 / 1024/1024,'FM999999.99')
From dba_segments t
where t.Segment_Name='表名'
Group By Segment_Name


可以利用java代码将上面的sql的结果拼凑成hive的建表语句,以及需要配置的conf
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: