日期:2014-05-16  浏览次数:20607 次

Oracle构造数据
#!/usr/bin/perl

#取系统时间函数

sub getsystime
{
     my ($sec,$min,$hour,$day,$mon,$year,$weekday,$yeardate,$savinglightday) = (localtime(time));
     my $year = $year+1900;
     my $output= sprintf("%4d%02d%02d%02d%02d%02d",$year,$mon,$day,$hour,$min,$sec);
     return $output;
}

#取随机时间函数

sub getrandtime        
{
     @yy = (2010..2014);
     @mm = (1..12);
     @dd = (1..31);
     @hh = (0..23);
     @mi = (0..59);
     @ss = (0..59); 
    
     my $sec  = $ss[int rand @ss];
     my $min  = $mi[int rand @mi];
     my $hour = $hh[int rand @hh];
     my $mon  = $mm[int rand @mm];
     if ( $mon == 2 )
     {   
         $day  = int(rand(27)) + 1;
     }
     elsif ( $mon == 1 || $mon == 3 || $mon == 5 || $mon == 7 || $mon == 8 || $mon == 10 || $mon == 12 )
     {
         $day  = int(rand(30)) + 1;
     }
     else
     {
         $day  = int(rand(29)) + 1;
     }    
     my $year = $yy[int rand @yy];
    
     #输出格式化后的时间    
     my $output = sprintf("%4d-%02d-%02d %02d:%02d:%02d",$year,$mon,$day,$hour,$min,$sec);
    
     #输出字符串形式的时间
     #my $output = sprintf("%4d%02d%02d%02d%02d%02d",$year,$mon,$day,$hour,$min,$sec);
    
     return $output;
}

#取随机数函数    

sub getrandnum
{
     if ( $_[0] > $_[1] )
     {
         $high_value = $_[0];
         $low_value = $_[1];
     }
     else
     {
         $high_value = $_[1];
         $low_value = $_[0];    
     }
    
     my $output = int(rand($high_value)) % ($high_value - $low_value) + $low_value;
    
     return $output;
}

#取定长随机字符函数

sub getrandchar
{
    @a = (0..9,'a'..'z','A'..'Z');
    $_vname = join '', map { $a[int rand @a] } 0..($_[0]-1);
    return $_vname;
}




#变量定义

@type_id = ("N1","N2","N3","N4","N5","N6","N7","N8","N9","N10","N11","N12","N13","N14","N15","N16");

$totalnum = 500000;    --指定生成的记录书
$tablename = "test";   --指定生成文件的名称