我想更新一个带有标志的表,只要标志为0,就更新该行。但是我的脚本遍历所有行,生成更新语句,但仅在最后一行执行更新statemnt。有谁看到我哪里出错了?
如果它有助于我将这个错误归结到最后一行:
DB-Library错误: 尝试启动具有挂起结果的新Adaptive Server操作 操作系统错误: 错误0
use Sybase::DBlib;
use Sys::Hostname;
use Getopt::Std;
## additionals
use ADDITIONALS;
my ($dsn, $database, $dbserver, $dbname, $user, $passwd, $rmdb_config ) = ('','','','','','','');
my ($table_name,$file_name) = ('','');
$dsn = "dbi:Sybase";
$database = join (' ~ ',$dsn, $dbserver, $dbname, $user, $passwd, $sda_config);
$dbhandle = connect_me($database);
my $ctl;
$ctl= "select Table_name = Table_name, Filename = Filename from table123 where Flag = '0'";
$dbhandle->dbcmd($ctl);
$dbhandle->dbsqlexec;
while($dbhandle->dbresults != NO_MORE_RESULTS){
while(%db_data = $dbhandle->dbnextrow(1)){
my $update ="update table123 set Flag = '1' where Flag ='0' and Filename ='$db_data{Filename}' ";
print $update."\n";
$dbhandle->dbcmd($update);
$dbhandle->dbsqlexec;
}
}
答案 0 :(得分:2)
您需要两个连接。一个用于选择,一个用于更新。这是错误消息告诉你的内容。您无法运行更新,因为您仍然有选择等待的结果。
在最后一行,所有结果都已被读取,您的连接可以自由运行最终更新。
但DBlib已经过时了两代技术。请尽可能使用DBI和DBD :: Sybase来更新系统。