• 用一个例子说明oracle临时表,创建过程,


    --创建临时表,规定好格式,是必须的,不同于sqlserver那么随意;
    Create Global Temporary Table record4
    (
      yljgdm VARCHAR2(22) not null,
      jzlsh VARCHAR2(50) not null,
      kh VARCHAR2(32),
      klx VARCHAR2(16),
      hzxm VARCHAR2(32),
      jzlx VARCHAR2(3),
      zzysgh VARCHAR2(16),
      zzysxm VARCHAR2(32),
      jzksmc VARCHAR2(30),
      jlgxsj DATE default Sysdate,
      zbdm VARCHAR(22)
    )
    on commit preserve rows;
     
    Create Global Temporary Table fee
    (
      jzlsh VARCHAR2(50) not null,
      mxxmje NUMBER(15,3) default 0,
      tfbz VARCHAR2(1) not null
     
    )
    on commit preserve rows;
     
     
    --运行经过调试的脚本,插入数据到临时表中
     
    insert into record4(yljgdm,jlgxsj,zzysgh,zzysxm,jzksmc,zbdm,jzlsh,kh,klx,hzxm,jzlx)
    select A.YLJGDM,A.JLGXSJ,A.ZZYSGH,A.ZZYSXM,A.JZKSMC,'MJZYZB',A.JZLSH,A.KH,A.KLX,A.HZXM,A.JZLX from CEN_CORE_V20.TB_YL_MZ_MEDICAL_RECORD A WHERE TO_CHAR(add_months(sysdate,-1),'yyyymm')=to_char(A.JLGXSJ,'yyyymm') ;
    --select * from record4;
     
    insert into fee
    select B.jzlsh,sum(B.mxxmje),B.TFBZ from CEN_CORE_V20.TB_HIS_MZ_FEE_DETAIL B where TO_CHAR(add_months(sysdate,-1),'yyyymm')=to_char(B.stfsj,'yyyymm') and B.Mxfylb in('12','13','14')
    group by B.jzlsh,B.TFBZ;
     
    --select * from fee;
     
    --select * from biolap.tb_yljg_sjzl_hz;
    --经过处理之后的数据,经过运行之后插入到目标表
    insert into biolap.tb_yljg_sjzl_hz(yljgdm,tjsj,ysgh,ysxm,ksmc,zbdm,jzlsh,kh,klx,hzxm,jzlx,mxxmje)
    select A.YLJGDM,to_char(A.JLGXSJ,'yyyymm'),A.Zzysgh,A.Zzysxm,A.JZKSMC,A.Zbdm,A.Jzlsh,A.Kh,A.Klx,A.Hzxm,A.Jzlx,
      sum(case when B.TFBZ='1' then B.MXXMJE when B.TFBZ='2' then -1*B.MXXMJE else 0 end ) je from record4 A,fee B
    where A.JZLSH=B.JZLSH
    group by a.yljgdm,to_char(A.JLGXSJ,'yyyymm'),A.Zzysgh,A.Zzysxm,A.Jzksmc,A.zbdm,A.jzlsh,A.kh,A.klx,A.Hzxm,A.Jzlx;
     
    --删除目标表中有可能出现问题的东西(其实不应该写在这里,但是因为程序的每次查询都要用到该列,所以这么写也可以)
    delete from biolap.tb_yljg_sjzl_hz where yljgdm is null;
     
    --提交
    commit;
    --这种preserve类型的临时表是以会话为单位的,就算提交,临时表中的数据还会存在
    --另一种delete类型的临时表,是以事务为单位的,提交之后表会仍然存在,但是表内部的数据就会清空
    --为了避免混乱,直接删除临时表,避免出现更新表结构之后提示表名被占用,或者错误的沿用上一次返回的数据
    drop table record4;
    drop table fee;
     
    --select * from biolap.tb_yljg_sjzl_hz where zbdm='MJZYZB'; 
  • 相关阅读:
    mongoDB Liunx下安装及配置
    Node.js WEB服务器(1)——编写简单的HTTP服务器
    MongoDB 和 NoSQL简介
    ES6的Promise浅析
    Node.js的模块系统
    Node.js的异步IO和事件轮询
    mybatis 关联表心得
    mustache 模板,用于构造html页面内容
    Python实现冒泡,选择排序
    文件路径太长无法删除 robocopy
  • 原文地址:https://www.cnblogs.com/zuopy/p/7765898.html
Copyright © 2020-2023  润新知