oracle到hive数据类型转换「建议收藏」

oracle到hive数据类型转换「建议收藏」oracle和hive中的数据类型存在差异,在oracle集成数据到hive中这样的场景下,我们希望在hive中的数据是贴源的,所以在hive中希望创建和oracle结构一致的表。oracle到hive数据类型映射参考如下:selectcasewhent1.column_id=1then’CREATETABLEIFNOTEXISTS’||’project’||’….


Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

oracle和hive中的数据类型存在差异,在oracle集成数据到hive中这样的场景下,我们希望在hive中的数据是贴源的,所以在hive中希望创建和oracle结构一致的表。

oracle到hive数据类型映射参考如下:

oracle到hive数据类型转换「建议收藏」

select case when t1.column_id=1 then 'CREATE TABLE IF NOT EXISTS '||'project'||'.'||t1.owner||'_'||t1.table_name||chr(10) end
||RPad(case when t1.column_id=1 then '(' else ',' end||t1.column_name,33,' ')
||RPad(case when t1.data_type in ('CHAR','VARCHAR2')     then 'VARCHAR('||t1.data_length||')' 
            when t1.data_type in ('TIMESTAMP(6)','DATE') then 'TIMESTAMP' 
			when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision =1 then 'TINYINT'
			when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision <4 then 'SMALLINT'
            when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision <9 then 'INT'
			when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision <19 then 'BIGINT'
            when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision >=19 then 'STRING'
            when t1.data_type ='NUMBER' and t1.data_scale>0 and t1.data_scale <=38 and t1.data_precision <=38 then 'DECIMAL('||t1.data_precision||','||t1.data_scale||')'
            when t1.data_type ='FLOAT'  then 'DOUBLE'
            else 'STRING' end,50,' ')
 ||' COMMENT '''||case when t4.column_name is not null then 'primary_key:' else '' end||replace(t2.comments,'''','')||''''
 ||case when max(t1.column_id) over() = t1.column_id then chr(10)||
 ',ETL_SJ STRING COMMENT ''ETL时间'')
 COMMENT '''||t3.comments||
 ''' 
PARTITIONED BY 
 (RFQ STRING COMMENT ''同步日期'');' end as col
  from sys.dba_tab_cols t1
 inner join sys.dba_col_comments t2 
    on t1.owner =t2.owner
   and t1.table_name = t2.table_name
   and t1.column_name = t2.column_name
 inner join sys.dba_tab_comments t3
    on t1.owner =t3.owner
   and t1.table_name = t3.table_name
  left join(
select t2.table_owner,t2.table_name,t2.column_name
  from (
select table_name,table_owner,index_name
,row_number() over(order by case when instr(index_name,'PK')>0 then instr(index_name,'PK') else 100 end asc) as cc
  from sys.dba_indexes
 where uniqueness  =upper('UNIQUE')
    and index_type ='NORMAL'
    and table_owner||'_'||table_name=upper('owner_table'))t1
  inner join sys.dba_ind_columns t2
    on t1.index_name =t2.index_name
   and t1.table_name =t2.table_name
   and t1.table_owner=t2.table_owner
 where t1.cc=1)t4
    on t1.owner      =t4.table_owner
   and t1.table_name =t4.table_name
   and t1.column_name=t4.column_name
 where t1.data_type not in ('LONG','NCLOB', 'CLOB','BLOB','BFILE','CFILE')
   and t1.owner||'_'||t1.table_name =upper('owner_table')
order by t1.column_id;
begin
    DBMS_OUTPUT.enable(BUFFER_SIZE => NULL);
  for i in (select owner||'_'||table_name tab from dba_tables where owner in (
'HX_ZS'
)) LOOP
   FOR J IN 
   (select case when t1.column_id=1 then 'CREATE TABLE IF NOT EXISTS '||'project'||'.'||t1.owner||'_'||t1.table_name||chr(10) end
||RPad(case when t1.column_id=1 then '(' else ',' end||case when t1.column_name='SJLYBZ' then 'SJLYBZ_1' else t1.column_name end,33,' ')
||RPad(case when t1.data_type in ('VARCHAR2')     then 'VARCHAR('||t1.data_length||')' 
      when t1.data_type in ('CHAR')     then 'CHAR('||t1.data_length||')'  
            when t1.data_type in ('TIMESTAMP(6)','DATE') then 'TIMESTAMP' 
      when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision =1 then 'TINYINT'
      when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision <4 then 'SMALLINT'
            when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision <9 then 'INT'
      when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision <19 then 'BIGINT'
            when t1.data_type ='NUMBER' and t1.data_scale=0 and t1.data_precision >=19 then 'DECIMAL('||t1.data_precision||','||t1.data_scale||')'
            when t1.data_type ='NUMBER' and t1.data_scale>0 and t1.data_scale <=38 and t1.data_precision <=38 then 'DECIMAL('||t1.data_precision||','||t1.data_scale||')'
            when t1.data_type ='FLOAT'  then 'DOUBLE'
            else 'STRING' end,50,' ')
 ||' COMMENT '''||case when t4.column_name is not null then 'primary_key:' else '' end||replace(t2.comments,'''','')||''''
 ||case when max(t1.column_id) over() = t1.column_id then chr(10)||
 ',YPTETL_SJ TIMESTAMP COMMENT  '||CHR(39)|| '云平台ETL时间'||CHR(39)||')
 COMMENT '''||t3.comments||
 ''' 
PARTITIONED BY 
  (rfq CHAR(8) COMMENT '||CHR(39)|| '日分区'||CHR(39)||',sjlybz VARCHAR(20)  COMMENT '||CHR(39)|| '数据来源标志'||CHR(39)||');' end as col
  from sys.dba_tab_cols t1
 inner join sys.dba_col_comments t2 
    on t1.owner =t2.owner
   and t1.table_name = t2.table_name
   and t1.column_name = t2.column_name
 inner join sys.dba_tab_comments t3
    on t1.owner =t3.owner
   and t1.table_name = t3.table_name
  left join(
select t2.table_owner,t2.table_name,t2.column_name
  from (
 select t6.owner table_owner, t6.table_name, t6.column_name
  from dba_constraints t5, dba_cons_columns t6
 where t5.table_name = t6.table_name
   and t5.owner = t6.owner
   and t5.constraint_name = t6.constraint_name
   and CONSTRAINT_TYPE IN ('P')
   and t5.OWNER ||'_'||t5.table_name =i.tab)t4
    on t1.owner      =t4.table_owner
   and t1.table_name =t4.table_name
   and t1.column_name=t4.column_name
 where t1.data_type not in ('LONG','NCLOB', 'CLOB','BLOB','BFILE','CFILE')
   and t1.owner||'_'||t1.table_name =i.tab
order by t1.column_id) loop
dbms_output.put_line(j.col);
end loop ;
end loop;
end;
/

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/191058.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 课程表课程设计_工程经济学课程设计

    课程表课程设计_工程经济学课程设计一、需求分析由于大学上课教室分散,学生经常会忘记自己的课程或是上课的教室。这在一定程度上促进学生课表软件的开发。使其可以帮助学生记录自己的课程和对自己课程的掌握。因为手机相对笔记本电脑更加具有便携性

    2022年8月3日
  • 了解匹配表

    了解匹配表

    2021年8月4日
  • [Halcon&标定] 单相机标定「建议收藏」

    [Halcon&标定] 单相机标定「建议收藏」为什么要进行单相机标定?广义:畸变矫正和一维和二维测量1)畸变矫正:    在几何光学和阴极射线管(CRT)显示中。畸变是对直线投影的一种偏移。简单来说直线投影是场景内的一条直线投影到图片上也保持为一条直线。那畸变简单来说就是一条直线投影到图片上不能保持为一条直线了。这是一种光学畸变(opticalaberration)。畸变是一种相差…

    2022年5月28日
  • java编写一个学生类和教师类_JAVA:1、编写一个学生类,类名为Student,包含如下成员:…

    java编写一个学生类和教师类_JAVA:1、编写一个学生类,类名为Student,包含如下成员:…1、编写一个学生类,类名为Student,包含如下成员:成员变量:1)变量名:name;类型:String;访问权限:private2)变量名:ID;类型:String;访问权限:private3)变量名:…1、编写一个学生类,类名为Student,包含如下成员:成员变量:1)变量名:name;类型:String;访问权限:private2)变量名:ID;类型:String;访问权限:pr…

    2022年7月8日
  • ARM 之七 主流编译器(armcc、iar、gcc for arm、LLVM(clang))详细介绍[通俗易懂]

    ARM 之七 主流编译器(armcc、iar、gcc for arm、LLVM(clang))详细介绍[通俗易懂]比较目前,针对于ARM平台的主流编译器主要有以下三者:比较ARMCCIARGCCforARM命令行工具IDE中,独立提供仅随其IDE发布,不独立提供独立提供开发商ARMIARGNU(目前由ARM维护)支持的平台Windows、LinuxWindowsWindows、Linux、Mac配套IDEKeilMDK、Develo…

    2022年6月10日
  • Java安全之Fastjson内网利用

    Java安全之Fastjson内网利用0x00前言在打Fastjson的时候,基本上都是使用JNDI注入的方式去打,也就是JdbcRowSetImpl链分析的链去打,但是遇到一些不出网的情况

    2021年12月13日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号