#!/usr/bin/perl
use diagnostics;
use DBI;
use DBI qw(:sql_types);
my $AIM_PSWD= $ENV{'AIM_PSWD'};
my $len=length($AIM_PSWD);
my $pwindex1=rindex($AIM_PSWD,'/');
my $pwindex2=rindex($AIM_PSWD,'@');
my $usr = substr($AIM_PSWD,0,$pwindex1);
my $pwd = substr($AIM_PSWD,$pwindex1+1,$pwindex2-($pwindex1+1));
my $db = substr($AIM_PSWD,$pwindex2+1,$len-($pwindex2+1));
my $attr = {AutoCommit => 0};
my $dbh;
my $qryHandle;
my $row;
my $query = "SELECT /*+ index(T_CAPITATION_HIST I_CAPITATION_HIST) */ SAK_CAPITATION FROM AIM.T_CAPITATION_HIST WHERE SAK_CAPITATION = ?";
$dbh = DBI->connect("dbi:Oracle:$db", $usr, $pwd, $attr)
or die "Unable to connect to $db\n";
$qryHandle = $dbh->prepare($query) or die "Unable to prepare query\n";
$qryHandle->bind_param(1, "765756556", {ora_type => SQL_VARCHAR});
$qryHandle->execute() or die "Unable to execute query\n";
if ($row = $qryHandle->fetchrow_hashref())
{
print "query succeeded\n";
}
else
{
print "query failed\n";
}
$qryHandle->finish();
$dbh->disconnect();
exit(0);
运行此命令会从bind_param语句生成错误消息: 用户代码未捕获的异常: 无法在./test.pl第26行绑定DBD :: Oracle不支持的:p1,ora_type 12。
如何确定支持哪些ora_type值?
答案 0 :(得分:3)
可用的ora_type值在https://metacpan.org/pod/DBD::Oracle#:ora_types处列出,并在https://metacpan.org/pod/DBD::Oracle#ora_type中进行了描述,并且必须从DBD :: Oracle导入,例如:
use DBD::Oracle ':ora_types';
如果要传递从DBI :sql_types
导入的标准SQL类型,只需将其直接作为绑定类型传递即可:
$qryHandle->bind_param(1, "765756556", SQL_VARCHAR);