当我从 cmd 运行以下 perl 脚本时收到上述错误消息,该脚本应该在我的数据库中执行一些事务。
#!/usr/bin/perl.
use warnings;
use strict;
my ( $pid1, $pid2, $pid3, $i ); #Declaration of local variables
$| = 1;
if ( ($pid1 = fork()) && ($pid2 = fork()) && ($pid3 = fork()) ) { #Starts child processes
print( "I have to wait for my kids.\n" ); #The main process execute this code
my $straggler = wait(); #The main process waits for all the children to finish
print( "Finally $straggler finished, now I can go.\n" );
}
elsif ( $pid1 && $pid2 && defined($pid3)) { #Is executed by the third child
sleep( 1 ); #Wait 1 second
print( "Start moving money between account 1 - 2" );
sleep(2);
for ($i=0; $i < 1000; $i++) { #Start transaction repeatedly
system("sqlcmd -S DESKTOP-U368A1B -Q tranKonto(1,2,100,1)"); #Moves 100 from account 1 to account 2
}
print( "End moving money between accounts trans 1 - 2 " );
exit();
}
else {
die( "Forking problems: " );
}
交易看起来像这样:
PROCEDURE [dbo].[tranKonto] @konto1 INT, @konto2 INT, @belopp INT, @isoLevel INT
AS
BEGIN TRANSACTION tranKonto
IF(@isoLevel=0)
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
ELSE IF (@isoLevel = 1)
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
ELSE IF (@isoLevel=2)
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
ELSE IF(@isoLevel=3)
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN
UPDATE Konto SET belopp=belopp-@belopp WHERE kontonr=@konto1
UPDATE Konto SET belopp=belopp+@belopp WHERE kontonr=@konto2
EXEC kontoLog_SP @konto1, @konto2 , @belopp , @isoLevel;
END
COMMIT TRANSACTION tranKonto
RETURN
运行脚本时出现以下错误消息:
消息 102,级别 15,状态 1,服务器 DESKTOP-U368A1B,第 1 行“1”附近的语法不正确。
如果有人能帮助我,我将不胜感激。我试图用谷歌搜索解决方案,但没有任何运气。
您应该删除存储过程参数周围的括号,并将调用用双引号引起来。在普通的命令行中,这看起来像:
由于这是在 perl 中,您需要转义引号: