gpt4 book ai didi

mysql - 如何在 Perl 中循环和重命名 MySQL 表

转载 作者:行者123 更新时间:2023-11-29 01:01:50 24 4
gpt4 key购买 nike

请教我如何在 Perl 中循环和重命名 MySQL 表。谢谢。

附上我的代码片段

use strict; 
use warnings;
use DBI;

my $dbh = DBI->connect(
'DBI:mysql:database=dbdev;host=localhost',
'dbdev',
'dbdevpw',
{ RaiseError => 1, AutoCommit => 1 },
);

my $sql = RENAME TABLE old_table TO new_table;
my $sth = $dbh->prepare($sql);

while (<DATA>){
chomp;
// How to implement the Rename all the old tables with the while loop.


$sth->execute();
}

最佳答案

我假设您的表列表存在于 DATA 中。

while (<DATA>){ 
chomp;
$dbh->do("RENAME TABLE ? TO ?", undef, $_, "new_" . $_);
}

您可能还想看看 perldoc DBI

关于mysql - 如何在 Perl 中循环和重命名 MySQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2645679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com