如何在Perl中

时间:2016-09-08 21:36:33

标签: perl dbi

我试图在子程序中使用两次相同的数据库句柄,但它给了我一个错误。任何帮助表示赞赏。

my $team1 =    $dbh->selectrow_array($SqlQueries::G_SQL_GET_CPP_TEAM, undef, @bind_values);
my $team2 =    $dbh->selectrow_array($SqlQueries::G_SQL_GET_CSHARP_TEAM, undef, @bind_values);
my $team = $team1 || $team2;

我基本上是尝试将team1分配给变量团队,但如果team1是undef,我想将其分配给team2。我试过这样的话:

以下代码位于package1。

my $team =    $dbh->selectrow_array($SqlQueries::G_SQL_GET_CPP_TEAM, undef, @bind_values) 
           || $dbh->selectrow_array($SqlQueries::G_SQL_GET_CSHARP_TEAM, undef, @bind_values);

以下SQL查询位于包SqlQueries.pm

Readonly our $G_SQL_GET_CPP_TEAM      => q{select top 1 team_name  from dbo.funcGetTeam('CPP','Department') where project_name = ? ;};
#funcGetTeam is the function created in SQL Server that takes two parameter and I have hardcoded them. 
Readonly our $G_SQL_GET_CSHARP_TEAM   => q{select top 1 team_name  from dbo.funcGetTeam('CSHARP','Department') where project_name = ? ;};

它给出了正确的结果,但也显示错误:

Use of uninitialized value in subroutine entry at C:/Perl/lib/DBD/ODBC.pm line
    229 (#1)
DBD::ODBC::db selectrow_array failed: called with 1 bind variables when 0 are needed at C:\stability\usr\lib/TeamMapping.pm line 106.

0 个答案:

没有答案