执行语句有问题。当我在命令提示符下运行时,它似乎永远挂起。它也不会死。执行可能需要参数吗?
#!/usr/bin/perl
use DBI;
use Data::Dumper;
$dbh = DBI->connect('DB', 'NAME', 'PASS',{ LongReadLen => 1000000} ) or die 'Error: cant connect to db';
$st= "update table set the_id = 7 where mid = 23 and tid = 22";
my $UpdateRecord = $dbh->prepare($st) or die "Couldn't prepare statement: $st".$dbh->errstr;
$UpdateRecord->execute() or die "can not execute $UpdateRecord".$dbh->errstr;
$UpdateRecord->finish;
$dbh->disconnect();
编辑:
我尝试在执行中绑定以及使用bind_param(),它仍然挂起。
答案 0 :(得分:0)
您需要do
而不是prepare
。
my $UpdatedRecord = $dbh->do($st) or die "Statement fails: $st".$dbh->errstr;
此方法通常对非SELECT语句最有用 要么不能提前准备(由于受到限制) 驱动程序)或不需要重复执行。它不应该 用于SELECT语句,因为它不返回语句 handle(因此您无法获取任何数据)。
此外,最好在use DBI;
语句之后添加/使用db驱动程序模块,即您正在使用的模块。
use DBD::Oracle
;
同时添加
使用严格;
使用警告;
答案 1 :(得分:0)
问题是我锁定了一堆对象,因为在我运行它之前没有把断开连接...是的,不要这样做。