把sqlserver中的存儲過程注釋后創(chuàng)建到mysql中
來源:易賢網(wǎng) 閱讀:1024 次 日期:2014-11-03 11:51:57
溫馨提示:易賢網(wǎng)小編為您整理了“把sqlserver中的存儲過程注釋后創(chuàng)建到mysql中”,方便廣大網(wǎng)友查閱!

把sqlserver中的存儲過程注釋后創(chuàng)建到mysql中

#!/usr/bin/perl

use DBI;

use Switch;

use Encode;

use Encode::CN;

my $source_name = "sqldb";

my $source_user_name = "sa";

my $source_user_psd = "123";

my $db_name="mysqldb";

my $location="192.168.0.208";

my $port="3306";

my $db_user="zoe";

my $db_pass="123";

my $dbh=DBI->connect("dbi:ODBC:$source_name",$source_user_name,$source_user_psd);

#獲取所有的用戶表

my $sth=$dbh->prepare("select name from sys.objects where type='P'");

$sth->execute();

my $n=0;

my $ok=0;

my $sort_column="";

while (@data=$sth->fetchrow_array())

{

#print $data[0];

print '正在查詢表'.$data[0]."的存儲過程n";

my $sql_create="EXEC Sp_HelpText '$data[0]'";

my $dbh_mssql=DBI->connect("dbi:ODBC:$source_name",$source_user_name,$source_user_psd,{RaiseError =>1});

$dbh_mssql->{LongTruncOk}=1;

$dbh_mssql->{LongReadLen}=1048576;

my $sth_select=$dbh_mssql->prepare($sql_create);

$sth_select->execute() or die 'Cannot execute: '. $sth_select->errstr();

my $select_col;

my $select_data;

while($select_data=$sth_select->fetchrow_array())

{

$select_col.=$select_data;

}

do_sql($data[0],$select_col);

}

$sth->finish;

$dbh ->disconnect;

print '所有表的存儲過程創(chuàng)建結束'."n";

sub do_sql

{

print '開始創(chuàng)建'.$_[0].'表的存儲過程'."n";

my $sql=$_[1];

open(FILE,"》createtableallproduce.txt");

syswrite(FILE,"$nn");

syswrite(FILE,"$data[0]n");

syswrite(FILE,"$sqln");

close(FILE);

$sql=~s//*/------注釋開始--------/g;

$sql=~s/*//------注釋結束--------/g;

$sql='CREATE PROCEDURE '.$_[0].'()'." n".' BEGIN '."n".' /* '.$sql.'*/'."n".'END; ';

my $data_base = "DBI:mysql:$db_name:$location:$port";

my $dbh3=DBI -> connect($data_base,$db_user,$db_pass);

$dbh3->do("SET character_set_client = 'utf8'");

$dbh3->do("SET character_set_connection = 'utf8'");

my $data_str=encode("utf-8",decode("gbk",$sql));

my $sth=$dbh3->prepare($sql);

open(FILE,"》myproduce.txt");

syswrite(FILE,"$nn");

syswrite(FILE,"$data[0]n");

syswrite(FILE,"$sqln");

close(FILE);

$sth->execute() or die "$data_str----ERROR::$data_str::$dbh3->errstr";

$dbh3->disconnect;

print '創(chuàng)建'.$_[0].'表的存儲過程結束'."n";

}

更多信息請查看IT技術專欄

更多信息請查看數(shù)據(jù)庫
易賢網(wǎng)手機網(wǎng)站地址:把sqlserver中的存儲過程注釋后創(chuàng)建到mysql中

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網(wǎng)