我创建了下面的DB2函数:
CREATE FUNCTION CLAIMS.get_gross_amount
(payment_option varchar(30),fy date, released date, grossamt int, taxamt int)
RETURNS INT
LANGUAGE SQL
DETERMINISTIC
CONTAINS SQL
CALLED ON NULL INPUT
BEGIN
declare gross_amt int;
declare tax_amt int;
IF (payment_option = 'overpayment')
THEN
if (fy = '2021' AND released <= '2020-06-30') then
SET gross_amt = grossamt;
elseif (fy = '2021' and (released >= '2020-07-01' and released <= '2021-06-30'))
then
SET gross_amt = grossamt - taxamt;
SET tax_amt = taxamt - 100;
end if;
ELSEIF (payment_option = 'underpayment' OR payment_option = 'backpayment')
THEN
if (fy = '2021' and (released >= '2020-07-01' and released <= '2021-06-30'))
then
SET gross_amt = grossamt - taxamt;
SET tax_amt = taxamt - 100;
end if;
ELSE
SET gross_amt = grossamt;
END IF;
RETURN gross_amt;
END
当我调用这个如下:
select claims.get_gross_amount('overpayment','2021','2020-06-30',1000,100) from SYSIBM.SYSDUMMY1;
我收到以下错误:
17:24:07 FAILED [SELECT - 0 rows, 300.297 secs] [Code: -911, SQL State: 40001] The current transaction has been rolled back because of a deadlock or timeout. Reason code "68".. SQLCODE=-911, SQLSTATE=40001, DRIVER=4.22.29
select claims.get_gross_amount('overpayment','2021','2020-06-30',1000,100) from SYSIBM.SYSDUMMY1;
为什么会出现死锁?
谢谢R
1条答案
按热度按时间t98cgbkg1#
如果您可以不断重复此操作,则可能会有一个打开的事务处理在您正在访问的某个行上获得了锁。您可以按以下方式检查长时间运行的事务处理: