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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • get和post的区别

    get和post的区别

    2021年8月30日
    52
  • teleport怎么用_telelist怎么用

    teleport怎么用_telelist怎么用teleport使用说明浏览器下载网页:只能浏览主页和少数网页,其它不能浏览,容量几百kbteleport下载项目一能完全离线看网页,7328多文件9个JPG文件,大小134Mteleport下载项目二部分网页采集内容和项目一基本一致,但大几兆部分网页需要项目二(复制站点)才能浏览,项目一看不到图片项目二比项目一耗时多,但要全面视频教程https…

    2022年9月8日
    0
  • c语言中的short是什么意思_c语言中short占几个字节

    c语言中的short是什么意思_c语言中short占几个字节Java中没有Int32,Int64,,只有int,short,longJava中int就代表Int32,short就代表Int16,long就代表Int64首先,几个基本的关键字:Int16=short,占2个字节.-32768~32767Int32=int,占4个字节.-2147483648~2147483647Int64=long,占8个字…

    2022年9月19日
    1
  • 新人如何入行3D游戏建模

    新人如何入行3D游戏建模所有行业都是一样的,没有什么容易的,只不过这一行是偏向于技术的,一个有好的建模师月薪10k+是很常见的,这个需要有自己刻苦学习的成果。游戏建模前景在游戏模型行业,你基本不用担心找不到工作,因为游戏模型师人才缺口非常大。举个例子:游戏制作公司的人员配比大多数是这样的:比如100人的三维制作组,可能有60人在做模型贴图,10个人在K动画。只要你保证技能在手,一定是抢手的人才。在几年前游戏建模这个行业不仅仅缺人才,甚至连新手都非常稀缺,那个时候公司愿意招聘实习生,培养他们然后给公司干活,但是工资一定不会给开的很

    2022年5月12日
    47
  • 基岩版服务器开启坐标显示,mc基岩版怎么看坐标 mc基岩版如何看坐标[通俗易懂]

    基岩版服务器开启坐标显示,mc基岩版怎么看坐标 mc基岩版如何看坐标[通俗易懂]mc基岩版如何看坐标我的世界地图有XYZ3个坐标,通过XYZ来显示你所处地图的区域。X-显示你在地图上的东/西位置,正数表示东,负数表示西。Y-显示你在地图上的海拔高度,整数表示位于地面上,负数表示位于地面下。Z-显示你在地图上的南/北位置,正数表示南,负数表示北。坐标可以显示为*位置和相对位置。02当坐标用数字显示时,则是*坐标,显示为地图上的特定地点。比如,1256163是一…

    2022年9月15日
    0
  • opencv-python图像二值化函数cv2.threshold函数详解及参数cv2.THRESH_OTSU使用「建议收藏」

    opencv-python图像二值化函数cv2.threshold函数详解及参数cv2.THRESH_OTSU使用「建议收藏」通常情况,我们一般不知道设定怎样的阈值thresh才能得到比较好的二值化效果,只能去试。如对于一幅双峰图像(理解为图像直方图中存在两个峰),我们指定的阈值应尽量在两个峰之间的峰谷#ret:暂时就认为是设定的thresh阈值,mask:二值化的图像ret,mask=cv2.threshold(img2gray,175,255,cv2.THRESH_BINARY)plt.imshow(mask,cmap=’gray’)上面代码的作用是,将灰度图img2gray中灰度值小于175的点置…

    2025年7月27日
    0

发表回复

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

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