[英]Update sql in perl script - execute statement stuck
Getting something is wrong with the execute statement. 执行语句有问题。 It just seems to hang forever when I run in command prompt. 当我在命令提示符下运行时,它似乎永远挂起。 It doesn't die either. 它也不会死。 does execute maybe need parameters? 是否执行可能需要参数?
#!/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();
EDIT: 编辑:
I tried binding in execute as well as using bind_param(), and it's still hanging up. 我尝试在执行中以及使用bind_param()进行绑定,但仍处于挂起状态。
you need a do
instead of prepare
. 您需要do
而不是prepare
。
my $UpdatedRecord = $dbh->do($st) or die "Statement fails: $st".$dbh->errstr;
This method is typically most useful for non-SELECT statements that either cannot be prepared in advance (due to a limitation of the driver) or do not need to be executed repeatedly. 对于非SELECT语句(由于驱动程序的限制而无法预先准备)或不需要重复执行的非SELECT语句,此方法通常最为有用。 It should not be used for SELECT statements because it does not return a statement handle (so you can't fetch any data). 不应将其用于SELECT语句,因为它不会返回语句句柄(因此您无法获取任何数据)。
Also it's always better to add/use db driver module,the one you are using, at top after use DBI;
另外,最好在use DBI;
之后在顶部添加/使用db driver模块use DBI;
statement. 声明。
use DBD::Oracle
; use DBD::Oracle
;
Also add 还添加
use strict; 使用严格
use warnings; 使用警告;
问题是我锁了一堆对象,以免在我运行一次断开连接之前无法将其插入。是的,不要那样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.