zoukankan      html  css  js  c++  java
  • LINUX使用SHELL对DB2数据库中的大表中的非月末数据进行分离

    #!/bin/sh
    
    . ./public_s.sh
    
    tdtp="zxjxhisdsspace1";  #tablespace
    titp="zxjxhisidxspace1"; #index tablespace 
    
    tbnm="plat_accinfosh";
    tb=$tbnm"_his";
    getlogname $0;
    log=$pub_result;
    
    [ "$1" != "" ] && tbnm=$1;
    
    pub_datatype="D";
    
    strdate=20130101
    enddate=20130228
    
    [ "$2" != "" ] && strdate=$2;
    [ "$3" != "" ] && enddate=$3;
    
    #获取两日间数据日期
    fc_getdayebtw  $strdate $enddate;
    days="$pub_result";
    
    #获取两月间数据日期
    pub_datatype="M";
    fc_getdayebtw  $strdate $enddate;
    mdays=$pub_result;
    
    
    tbexist="N";
    
    pub_debug="N";
    
    #判断是否存在表
    callchktb()
    {
      chtb=$1;
      
      if [ "$chtb" = "" ]
      then 
        echo "chtb is empty !exit!";
        exit;
      fi;
      
      if [ "$tbexist" = "N" ]
      then
         #检查表是否存在,表的格式为$tbname+his
         
         sql="select count(1) from syscat.tables a where a.tabname=upper('$chtb')";
         echo "sql is [$sql]" | tee -a $log;
         db2cmd "$sql";
         [ "$pub_result" = "1" ] && tbexist="Y";
         
    echo "chtb is $chtb and pub_result [$pub_result] ";
      fi;
    }
    
    #创建表
    callcreate()
    {
        createtsql=" create table $ctbnm like $tbnm in $tdtp index in $titp";
        echo "$createtsql" | tee -a $log;
        db2cmd "$createtsql";
        echo "$pub_result" | tee -a $log;
        echo "$pub_sqlcode" | tee -a $log;
    }
    
    
    #插入函数
    callinsert()
    {
      cdate=$1;
      ctbnm=$2;
      
      if [ "$cdate" = "" -o "$ctbnm" = "" ]
      then
         echo "cdate or ctbnm is empty" | tee -a $log;
         exit;
      fi;
    
      #检查表是否存在,表的格式为$tbname+his
      callchktb $ctbnm;
      #echo "1........"
      if [ "$tbexist" = "N" ]
      then
        callcreate $ctbnm;
        #echo "10........"
      fi;
      callchktb $ctbnm;
      #echo "2........"
      
      if [ "$tbexist" = "Y" ]
      then
      #echo "3........"
        insertsql=" insert into $ctbnm 
                    select * from $tbnm where datadate=$cdate 
                     and not exists ( select 1 from $ctbnm where datadate=$cdate fetch first 1 rows only)
                     with ur";
        echo "$insertsql" | tee -a $log;
        db2cmd "$insertsql" ;
        echo "$pub_result" | tee -a $log;
        echo "$pub_sqlcode" | tee -a $log;
      fi;
      
      detesql="delete from $tbnm where datadate=$cdate and exists ( select 1 from $ctbnm where datadate=$cdate)"
      db2cmd "$detesql";
      echo "$detesql" | tee -a $log;
      echo "$pub_result" | tee -a $log; 
      echo "$pub_sqlcode" | tee -a $log;
    } 
    
    #echo days is [$days]
    #echo mdays is [$mdays]
    #exit;
    for d in $days
    do
      #去除每个月底数据,其他的数据插入到历史表中
      for f2d in $mdays
      do          
        [ "$d" = "$f2d" ] && continue 2;
      done;
      echo callinsert $d $tb;
      callinsert $d $tb;
    done
    db2cmd "runstats on table zxjx.$tb";
  • 相关阅读:
    踏个脚印,今天在博客园安了个家!
    微软WebDeployment Project插件发布网站时老是报出"aspnet_merge.exe”已退出,代码为1的错误
    从xap文件中读取文件
    ASP.NET MVC学习笔记二(URL映射规则)
    Siverlight Contrib的alpha版与正式版有很大区别
    带你尝鲜LiteOS 组件EasyFlash
    带你了解几种二进制代码相似度比较技术
    让数据大白于天下:GCC插件实现代码分析和安全审计
    鸿蒙轻内核源码分析:MMU协处理器
    高性能云网关,打通云内外业务互通的任督二脉
  • 原文地址:https://www.cnblogs.com/silencemaker/p/12632010.html
Copyright © 2011-2022 走看看