#!/usr/bin/perl
use DBI;
use Encode;
my $dbName = 'oadb';
my $dbUser = 'vxspace';
my $dbUserPass = 'xxx';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";
my $table_name= "$ARGV[0]";
my $hostSql = qq{select COLUMN_NAME from dba_tab_columns where table_name='$table_name'};
my $UNLOAD_SRC_DBCONN = DBI->connect("DBI:Oracle:".$dbName,$dbUser,$dbUserPass) or die("DB connect error!n");
my $DW_DATA_DT ="";
my $datafile="$table_name.TXT";
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my @lstRlst;
my ($COLUMN_NAME);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->bind_columns(undef, \$COLUMN_NAME);
$selStmt->execute();
while( $selStmt->fetch() ){
print "$COLUMN_NAME\n";
push (@lstRlst1 ,$COLUMN_NAME);
}
$selStmt->finish;
$dbh->disconnect;
my @lstRlst = reverse (@lstRlst1);
##########################################
#=================全局变量区==========================#
if ($#ARGV <0){
print "请输入一个表名参数";
exit(-1);
}
sub printlog
{
my ($LogInfo)= @_;
my $CurrTime = time2iso(time()); # 当前时间
if(!defined($LogInfo) ){$LogInfo="";}
my $StrLog="【${CurrTime}】 \t ${LogInfo} \n"; print $StrLog;
#print LOGFILE $StrLog;
} my $exportOracleSql="SELECT "; #数据导出的sql
for (my $m=0;$m<@lstRlst + 0 ;$m++){
if ($m != @lstRlst + 0 - 1){
$exportOracleSql = "$exportOracleSql trim($lstRlst[$m])".", "
}
else{
$exportOracleSql = "$exportOracleSql trim($lstRlst[$m])"}
print "$exportOracleSql\n";
}
my $exportOracleSql="$exportOracleSql from $dbUser.$table_name"; sub Exportdata{
printlog "开始导出数据!";
my $exportsql=$exportOracleSql;
if($exportsql eq "error"){
return -1;
}
my $format_sql="alter session set nls_date_format='yyyy-mm-dd'";
my $stmt=$UNLOAD_SRC_DBCONN->prepare($format_sql);
unless ($stmt){
printlog "\n执行prepare SQL语句出错:\n";
printlog $DBI::errstr;
return -1;
}
$stmt->execute;
if ($UNLOAD_SRC_DBCONN->err) {
printlog "\n执行SQL语句出错:\n";
printlog $DBI::errstr;
return -1;
}
$stmt=$UNLOAD_SRC_DBCONN->prepare($exportsql);
unless ($stmt){
printlog "\n执行prepare SQL语句出错:\n";
printlog $DBI::errstr;
return -1;
}
$stmt->execute;
if ($UNLOAD_SRC_DBCONN->err) {
printlog "\n执行SQL语句出错:\n";
printlog $DBI::errstr; return -1;
}
my $row=0;
my $size=0;
my $curtime; my $writeflagsql;
my $tmpstr="";
$row=0;
my $m=0;
open(DATAFILE,">", $datafile) || die (print "Open DATA file failed!!!\n");
while(my $Rows = $stmt->fetchrow_arrayref){
$m=0;
$tmpstr="";
foreach(@$Rows){
$tmpstr=$tmpstr.$Rows->[$m]."|";
$m++;
}
#print DATAFILE encode_utf8($tmpstr.$DW_DATA_DT)."\n";
print DATAFILE $tmpstr.$DW_DATA_DT."\n";
$row++;
if(($row%10000) == 0){
printlog "已导出数据$row条!";
}
} $stmt->finish;
# print FLAGFILE $datafile,"\n";
# print FLAGFILE $row,"\n";
close(DATAFILE);
# close(FLAGFILE); $curtime=time2iso(time());
printlog "数据已成功导出!";
printlog "一共导出数据${row}条"; return 1; }
Exportdata Wide character in print at unload_oracle.pl line 105.
Wide character in print at unload_oracle.pl line 105.
Wide character in print at unload_oracle.pl line 105.
【2016-11-17 19:02:25】 数据已成功导出!
【2016-11-17 19:02:25】 一共导出数据3726条 需要encode_utf8($tmpstr.$DW_DATA_DT)."\n";

perl unload utf-8 oracle Wide character in print at unload_oracle.pl line 105.的更多相关文章

  1. Wide character in print at a2.pl line 返回json 需要encode_utf8

    centos6.5:/root/test#cat a2.pl use Net::SMTP; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Heade ...

  2. Wide character in print at a2.pl line 6.

    jrhapt01:/home/tomcat/test> cat a2.pl my $str="$ARGV[0]"; use Encode; use URI::Escape; ...

  3. Wide character in print at hcp.pl line 21.

    jrhmpt01:/root# cat -n hcp.pl 1 use LWP::UserAgent; 2 use Encode; 3 $ua = LWP::UserAgent->new; 4 ...

  4. 为什么出现Wide character in print at a14.pl line 41

    [root@wx03 ~]# cat a14.pl use Net::SMTP; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; u ...

  5. php 返回json 解析 报Wide character in print

    php 返回json: zabbix:/var/www/html/DEVOPS/Home/Lib/Action# vim EquipmentAction.class.php <?php head ...

  6. perl unload utf-8 oracle 数据库

    perl unload utf-8 Oracle [oracle@oadb sbin]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Produc ...

  7. perl unload gbk oracle 数据库

    perl unload gbk Oracle 数据库 use Encode; if ( $#ARGV < 0 ){ print "请输入一个文件\n"; exit(-1); ...

  8. error: converting to execution character set: Invalid or incomplete multibyte or wide character

    交叉编译.c文件,遇到如下问题 arm-linux-gcc -o show_lines show_lines.c -lfreetype -lm show_lines.c:199:19: error: ...

  9. Can't locate find.pl in @INC (@INC contains: /etc/perl xxxx) at perlpath.pl line 7.

    /********************************************************************** * Can't locate find.pl in @I ...

随机推荐

  1. C# 操作数据库的几种方式(数据库使用SQL SERVER2008)

    一:通过常规 T-SQL 语句 (只写删除操作,其他同理) string strConn = ConfigurationManager.ConnectionStrings["SiteConn ...

  2. 20160410javaweb之JDBC---DBUtils框架

    DBUtils 1.DbUtils 工具类 2.QueryRunner -- 两行代码搞定增删改查 (1)QueryRunner() --需要控制事务时,使用这组方法 int update(Conne ...

  3. 20151217jquery学习笔记--注册表单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. python中关于正则表达式三

    2015年8月14日 11:10 7.2正则表达式操作 正则表达式使用反斜杠字符'\'来暗示一些特殊的形式或者允许特殊的字符使用但是没有调用它们特殊的意思.在字符串常量中的相同目标的字符的python ...

  5. oc for in 的时候nsscanner: nil string argument

    今天偶然发现,oc for in 动态的给一数组加东西,然后嵌套for in 会报nsscanner: nil string argument. 换成for循环就好了,暂时还没找到原因

  6. MinGW-notepad++开发c/c++程序

    下载MinGW 点击下载 安装好后运行 最后点击左上角的 Installation,开始安装 1.编译: g++ -o a.exe a.cpp gcc -o hello.exe hello.c 2.运 ...

  7. Spring配置,JDBC数据源及事务

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. javaee学习-JSP指令简介

    JSP指令(directive)是为JSP引擎而设计的,它们并不直接产生任何可见输出,而只是告诉引擎如何处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指令: page指令 Inclu ...

  9. 学习笔记---C++伪函数(函数对象)

    C++里面的伪函数(函数对象)其实就是一个类重载了()运算符,这样类的对象在使用()操作符时,看起来就像一个函数调用一样,这就叫做伪函数. class Hello{ public: void oper ...

  10. RSA安全性问题

    加密:C=Me(mod n) 解密:M=Cd(mod n) 安全性基础: 穷举法攻击: 1.攻击者设计一个M,C=Me(mod n) 2.d的个数至多有n-1个,尝试使用每个d破解,如果M’=Cd‘( ...