mysql中的表导出为csv_将数据库中的表中的数据导出为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-${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==================='

附件列表

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值