Oracle create table 语句转换为 HIVE create table语句 以及 insert 和select 语句
SELECT
'CREATE EXTERNAL TABLE IF NOT EXISTS DWD_FACT_SUPPLYCHAIN_WMS.DWD_FACT_SUPPLYCHAIN_WMS_' || table_name || chr( 13 ) || '(' || RTRIM(
XMLAGG( XMLPARSE ( CONTENT ( column_name || chr( 9 ) || DATA_TYPE || chr( 10 ) || ',' ) WELLFORMED ) ORDER BY column_id ).GETCLOBVAL ( ),
','
) || ')' || 'COMMENT ' || '"' || tab_comments || '"' || chr( 10 ) || 'ROW FORMAT DELIMITED' || chr( 10 ) || 'FIELDS TERMINATED BY ''#''' || chr( 10 ) || 'STORED AS TEXTFILE;' || chr( 10 ) || chr( 10 ) ||'INSERT OVERWRITE table DWD_FACT_SUPPLYCHAIN_WMS.DWD_FACT_SUPPLYCHAIN_WMS_' || table_name || chr( 10 ) || 'select * from ods_ny_supplychain_wms.' || table_name AS sq,
table_name
FROM
(
SELECT
col.table_name,
col.COLUMN_NAME,
decode( col.DATA_TYPE, 'NUMBER', 'DOUBLE', 'TIMESTAMP(6)', 'TIMESTAMP' ) ||
CASE
WHEN DATA_TYPE = 'NUMBER' THEN
-- '(' || nvl( to_char( DATA_PRECISION ), 22 ) || ',' || to_char( NVL( COL.data_scale, 0 ) ) || ')'
''
WHEN LOWER( col.COLUMN_NAME ) IN ( 'inserttime', 'updatetime','createtime' ) THEN
' TIMESTAMP'
WHEN data_type IN ( 'DATE', 'TIMESTAMP(6)' ) THEN
' TIMESTAMP' ELSE ' STRING'
END || ' COMMENT ' || '''' || cms.COMMENTS || '''' || CHR( 13 ) AS DATA_TYPE,
col.COLUMN_ID,
tms.COMMENTS AS tab_comments
FROM
all_tab_columns col
JOIN all_col_comments cms ON col.TABLE_NAME = cms.table_name
AND col.COLUMN_NAME = cms.COLUMN_NAME
AND col.OWNER = cms.OWNER
JOIN all_tab_comments tms ON col.TABLE_NAME = tms.TABLE_NAME
AND col.OWNER = tms.OWNER
WHERE
COL.TABLE_NAME LIKE upper( 'TB_BASIC_SAP_COMPANY' )
AND regexp_substr( tms.table_name, '[0-9]+' ) IS NULL
AND col.OWNER = 'WMSUSER'
)
GROUP BY
table_name,
tab_comments
ORDER BY
table_name;
注意:标红的 1. 表名
2.表空间
转换结果:
CREATE EXTERNAL TABLE IF NOT EXISTS DWD_FACT_SUPPLYCHAIN_WMS.DWD_FACT_SUPPLYCHAIN_WMS_TB_BASIC_SAP_COMPANY (ID DOUBLE COMMENT 'id'
,CODE STRING COMMENT '公司代码'
,NAME STRING COMMENT '公司名称'
,CITY STRING COMMENT '城市'
,CURRENCY STRING COMMENT '货币'
,CREATER DOUBLE COMMENT '创建人id'
,CREATETIME TIMESTAMP COMMENT '创建时间'
,EDITOR DOUBLE COMMENT '最后修改人id'
,EDITTIME STRING COMMENT '最后修改时间'
,ISDEL DOUBLE COMMENT '删除标记,0有效,1删除'
,ISTRUE DOUBLE COMMENT '是否有效,0有效,1失效'
,SHORTNAME STRING COMMENT '简称'
)COMMENT "SAP公司信息"
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '#'
STORED AS TEXTFILE;
INSERT OVERWRITE table DWD_FACT_SUPPLYCHAIN_WMS.DWD_FACT_SUPPLYCHAIN_WMS_TB_BASIC_SAP_COMPANY
select * from ods_ny_supplychain_wms.TB_BASIC_SAP_COMPANY
注意:数仓规范的命名
ods_XXX
dwd_XXX
dws_XXX
Sqoop脚本的命名:Sqoop_ods_XXX
事实表: dwd_fact_XXX
维度表: pub_dim_XXX