sqlserver数据导入mysql八: 把sqlserver中的存储过程注释后创建到mysql中(留着人工修改)

sqlserver数据导入mysql八: 把sqlserver中的存储过程注释后创建到mysql中(留着人工修改),第1张

概述#!/usr/bin/perluse 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.16
#!/usr/bin/perluse 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_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 '所有表的存储过程创建结束'."\n";   sub do_sql  {    print '开始创建'.$_[0].'表的存储过程'."\n";    my $sql=$_[1];    	 open(file,">>createtableallproduce.txt");  syswrite(file,"$n\n");  syswrite(file,"$data[0]\n");  syswrite(file,"$sql\n");  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,"$sql\n");  close(file);		$sth->execute() or dIE "$data_str----ERROR::$data_str::$dbh3->errstr";	$dbh3->disconnect; 		          print '创建'.$_[0].'表的存储过程结束'."\n";  }
总结

以上是内存溢出为你收集整理的sqlserver数据导入mysql八: 把sqlserver中的存储过程注释后创建到mysql中(留着人工修改)全部内容,希望文章能够帮你解决sqlserver数据导入mysql八: 把sqlserver中的存储过程注释后创建到mysql中(留着人工修改)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1170220.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存