[英]Syntax error when creating a stored procedure in IBM DB2
我無法執行該過程,錯誤指出:
在“ent.payment_id)*0.50”之后發現了意外標記“END-OF-STATEMENT”。 預期的令牌可能包括:“”。 行號=6。 SQLSTATE=42601。
此過程是在代碼有效時更新總價。 我嘗試了兩種方法。 任何人都可以幫忙嗎?
create procedure Prc_Discount(in code char(3), payment_id integer)
begin
if (code ='abc')then
update payment
set new.total_price =(select total_price from payment
where new.payment_id=payment.payment_id)*0.50;
else
if (code ='bac')then
update payment
set new.total_price =(select total_price from payment
where new.payment_id=payment.payment_id)*0.75;
else
if (code ='cba')then
update payment
set new.total_price =(select total_price from payment
where new.payment_id=payment.payment_id)*0.90;
end if;
end@
另一種嘗試:
create procedure Prc_Discount(in code char(3), payment_id integer)
begin
case code
when abc then
update payment
set new.total_price =(select total_price from payment
where new.payment_id=payment.payment_id)*0.50;
when acd then
update payment
set new.total_price =(select total_price from payment
where new.payment_id=payment.payment_id)*0.75;
else
update payment
set new.total_price =(select total_price from payment
where new.payment_id=payment.payment_id)*0.90;
end case;
end@
在你的程序中試試這個
update payment f1
set f1.total_price =
case
when code ='abc' then 0.50 * f1.total_price
when code ='bac' then 0.75 * f1.total_price
when code ='cba' then 0.90 * f1.total_price
else f1.total_price
end
where code in ('abc', 'bac', 'cba')
嘗試將其放在上面的代碼中:
“——”
用“結束”替換“結束@”;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.