zoukankan      html  css  js  c++  java
  • perl 通过生成mysql 批量sql

    zabbix:/root/sbin# perl t1.pl  20160101 20160105
    create table test1.test_20160101;
    create table test1.test_20160102;
    create table test1.test_20160103;
    create table test1.test_20160104;
    create table test1.test_20160105;
    create table test2.test_20160101;
    create table test2.test_20160102;
    create table test2.test_20160103;
    create table test2.test_20160104;
    create table test2.test_20160105;
    create table test3.test_20160101;
    create table test3.test_20160102;
    create table test3.test_20160103;
    create table test3.test_20160104;
    create table test3.test_20160105;
    zabbix:/root/sbin# cat t1.pl 
    use DBI;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    my $ip="127.0.0.1";
    my $user="root";
    my $passwd="1234567";
    my $dbh = DBI->connect("dbi:mysql:database=$message;host=$ip;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
    ##防止utf-8中文乱码
    $dbh->do("SET NAMES utf8");
    my $date1= "$ARGV[0]";
    my $date2="$ARGV[1]";
    my $date=$date1;
    my $tip='+1';
     sub get_date{ 
           my $var_date=$_[0]; 
           my $hostSql = qq{  SELECT DATE_FORMAT( DATE_ADD( '$var_date', INTERVAL $tip  DAY), '%Y%m%d') AS xxx FROM information_schema.tables a limit 1;};
           my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);    
           my $selStmt = $dbh->prepare($hostSql);    
           $selStmt->execute();    
           while (@recs=$selStmt->fetchrow_array) {
           foreach (@recs)
           {$date=$_;return $date}
    };
    };
        for ($i=1;$i<=3;$i++){
        while (1==1){
        $date3=$date;
        print "create table test$i.test_$date3;
    ";
        $date=&get_date($date3);
        if ( "$date" == "$date2" ){print "create table test$i.test_$date;
    ";$date="$date1";last;}
       };
       };

  • 相关阅读:
    Oracle 学习笔记4 SQL语言基础
    Oracle 学习笔记3 Sql Plus 命令
    连接扩展屏后,桌面上的图标自动跑到扩展屏上去了
    Oracle数据库基础知识
    ORACLE 学习笔记 2 Oracle 11g 体系结构
    EXCEL 连接Oracle 数据库
    虚拟机
    截取默写数据库无法识别的字符前几位的值
    c#的SerialPort在多线程环境下需要加锁
    32. 最长有效括号
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349946.html
Copyright © 2011-2022 走看看