zoukankan      html  css  js  c++  java
  • 将数据库中的表中的数据导出为csv文本

    #!/bin/bash
    #========Usage: sh exp.sh 264  Or ./exp.sh 264  import data from records in tables which was inserted in 265 to 264 days before sysdate  ======#
    
    if (($# == 0));then
    echo '===========you need to  input an integer parameter ============='
    exit 1
    fi
    
    echo '===========beginning of exporting data from tables==================='
    
    #prev_date
    prev_date=`date -d "-$1 day" +%Y-%m-%d`
    
    end_day=$(($1-1))
    start_day=$1
    
    export ORACLE_HOME=/u01/app/11.2.0/db_home1
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib
    
    #program path
    prog_path=/home/oracle/lxm/imp_exp
    
    #output file base path
    output_file_base_path=${prog_path}/file
    
    #log path
    output_log_base_path=${prog_path}/logs
    
    #db link string
    db_srv="ddjk/czty_ddjk@ddcx"
    
    
    arr=(t_sagw_callreleasepush_msg t_smb_sub_msg  t_smb_unsub_msg t_sagw_cdrpush_msg)
    
    for var in ${arr[@]};  
    do  
            output_file=${output_file_base_path}/${var}/${var}_${prev_date}".txt"
            output_log=${output_log_base_path}/${var}/${var}".log"
            echo $output_file
            if [ ! -f $output_file ];then
                    touch $output_file
            fi  
            echo $output_log
            if [ ! -f $output_log ];then
                    touch $output_log
            fi  
          # sql="select * from ${var} t where t.time<sysdate-${end_day} and  t.time>=sysdate-${start_day}"
            sql="select * from ${var} t where t.time < to_date(to_char(sysdate,'yyyy/mm/dd'), 'yyyy/mm/dd')-${end_day} and  t.time>=to_date(to_char(sysdate,'yyyy/mm/dd'), 'yyyy/mm/dd')-${start_day}"
    
            $prog_path/sqluldr2_linux64_10204.bin user=$db_srv query="$sql" file=$output_file field=0x2c record=0x0a log=$output_log charset=ZHS16GBK txt=unl
    done
    echo '===========end of exporting data from tables==================='

    附件列表

    • 相关阅读:
      matlab图像对比度增强,拉伸和灰度变换
      javascript 数据结构----集合
      reduce ,redceRight 在react中的使用
      找前端私活
      数组对象 按某个属性排序
      原生js获取scrollTop
      react 绑定事件 总是默认触发
      横向柱状图
      css 四角辉光
      Android学习笔记_点九绘图与软键盘和事件传递
    • 原文地址:https://www.cnblogs.com/yldf/p/7883482.html
    Copyright © 2011-2022 走看看