sqlserver数据导入mysql三: 把生成的表分成几份
- UID
- 1066743
|
sqlserver数据导入mysql三: 把生成的表分成几份
#!/usr/bin/perl
use Encode;
use Encode::CN;
use DBI;
use Switch;
use strict;
use Net::HandlerSocket;
use threads;
use Time::HiRes 'time';
print "请输入数字确认要把所有表分成几份";
my $var=0;
$var=<STDIN>;
chop ($var);
print "请输入总表名";
my $read=0;
$read=<STDIN>;
chop ($read);
my $readtxtname=$read;
my @a;
open(FILE,"$readtxtname");
while (<FILE>) {
chomp;
if(defined($_ ))
{
push @a,$_;
}
}
close(FILE);
my $many=int(@a/$var);
my $count=@a;
print $many."\n";
print $count."\n";
my $i=1;
while($i<=$var){
my $outtxtname="alltablename_exportname_"."$i"."\.txt";
my $index=$many*($i-1);
if($i==$var)
{
while($index<=@a-1){
open(FILE,">>$outtxtname");
syswrite(FILE,"@a[$index]\n");
syswrite(FILE,"@a[$index+1]\n");
close(FILE);
$index=$index+2;
}
}
else
{
while($index<=$many*$i-1){
open(FILE,">>$outtxtname");
syswrite(FILE,"@a[$index]\n");
syswrite(FILE,"@a[$index+1]\n");
close(FILE);
$index=$index+2;
}
}
$i++;
}
print "ok"; |
|
|
|
|
|