Perl DBI中MS SQL Server存储过程的绑定参数问题

时间:2022-10-21 11:23:57

Getting error while executing the stored procedure from perl. I am able to connect to the MS SQL server from perl without any issues. But when I execute the procedure with the following binding parameters I am getting the error

从perl执行存储过程时出错。我可以从perl连接到MS SQL服务器,没有任何问题。但是当我使用以下绑定参数执行该过程时,我收到错误

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '@id'. (SQL-42000)

[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]'@id'附近的语法不正确。 (SQL-42000)

this 'id' is the first parameter. When I look at the procedure it is fine. Anyone have any thoughts on this error?

这个'id'是第一个参数。当我看这个程序时,它很好。有人对此错误有任何想法吗?

Code

#GetStatusDescription(?, ?, ?) - id - LONG, status - VARCHAR, description - VARCHAR
my $sth = $dbh -> prepare('exec GetStatusDescription(?, ?, ?)');
my $str1, my $str2;
my $intid = 11122;
use DBI qw(:sql_types);
$sth->bind_param(1, $intid, DBI::SQL_INTEGER); 
$sth->bind_param_inout(2, \$str1, DBI::SQL_VARCHAR); 
$sth->bind_param_inout(3, \$str2, DBI::SQL_VARCHAR); 
$sth->execute() or die $dbh -> errstr;

1 个解决方案

#1


3  

If you're calling to a stored procedure, those don't take parentheses in SQL Server. that is, you want:

如果您正在调用存储过程,那些不会在SQL Server中使用括号。也就是说,你想要:

my $sth = $dbh -> prepare('exec GetStatusDescription ?, ?, ?');

#1


3  

If you're calling to a stored procedure, those don't take parentheses in SQL Server. that is, you want:

如果您正在调用存储过程,那些不会在SQL Server中使用括号。也就是说,你想要:

my $sth = $dbh -> prepare('exec GetStatusDescription ?, ?, ?');