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

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

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

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)
上一篇 2026年2月8日 下午6:15
下一篇 2026年2月8日 下午6:43


相关推荐

  • netstat命令总结

    netstat命令总结简介 1 netstat 是一个监控 TCP IP 网络的非常有用的命令 它可以显示路由表 实际的网络连接以及每一个网络接口设备的状态信息 Netstat 用于显示与 IP TCP UDP 和 ICMP 协议相关的统计数据 一般用于检验本机各端口的网络连接情况 2 netstat 中的各个参数可以组合使用 具体请参考本博客的举例执行下 netstat 命令后结果如下图 netstat 的输出结果可以分为两个部分 上图中已经用两个红框标识出来了 1 ActiveIntern 即有

    2026年3月17日
    1
  • java 哈希码

    java 哈希码哈希码产生的依据 哈希码并不是完全唯一的 它是一种算法 让同一个类的对象按照自己不同的特征尽量的有不同的哈希码 但不表示不同的对象哈希码完全不同 也有相同的情况 看程序员如何写哈希码的算法

    2026年3月17日
    2
  • gis地理加权回归步骤_地理加权回归权重

    gis地理加权回归步骤_地理加权回归权重内容导读1)回归概念介绍;2)探索性回归工具(解释变量的选择)使用;3)广义线性回归工具(GLR)使用;*加更:广义线性回归工具的补充内容4)地理加权回归工具(GWR)使用+小结。说明:本节是这个学习笔记最后一部分。PART/04地理加权回归工具(GWR)使用上一节我们讲了GLR广义线性回归,它是一种全局模型,可以构造出最佳描述研究区域中整体数据关系的方程。如果这些关系在研究区域中是一致的,则GLR回归方程可以对这些关系进行很好的建模。不过,当这些关系在研

    2022年10月6日
    8
  • 无法获得下列许可 solidworks_2019年个人总结

    无法获得下列许可 solidworks_2019年个人总结通常,按照网上教程来安装SolidWorks2019、2020到最后启动软件有可能会出现这个错误;下面提供本人亲测可用、在用的解决办法供各位参考。1.如果弹出该错误提示时,先检查“SolidWorks_Flexnet_Server”这个文件夹的所在路径,建议移动到SolidWorks的安装根目录下,即“SOLIDWORKSCorp”目录下。因自身原因无法移动的,请勿删除该文件夹,否则会激活…

    2026年2月13日
    3
  • c++截取字符串[通俗易懂]

    c++截取字符串[通俗易懂]C++的string类提供了大量的字符串操作函数,提取字符串的一部分,可采用substr函数实现

    2022年5月10日
    66
  • 4月第3周业务风控关注 | 文化部再次审查直播和游戏产品,已下架4939款直播应用…

    4月第3周业务风控关注 | 文化部再次审查直播和游戏产品,已下架4939款直播应用…

    2021年5月27日
    112

发表回复

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

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