【问题标题】:Syntax error when creating a stored procedure in IBM DB2在 IBM DB2 中创建存储过程时出现语法错误
【发布时间】:2017-02-01 14:08:20
【问题描述】:

我无法执行程序,错误状态:

在“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@

【问题讨论】:

  • 这个 Java 有什么关系?
  • @HovercraftFullOfEels 抱歉,根本不相关。
  • 那么请删除令人困惑的Java问题标签。我不能这样做,因为您的问题有待修改。
  • 为什么不能执行程序?你不知道怎么做?您的数据库是否已启动并正在运行?可以连接吗?
  • @mustaccio 我无法执行该过程,它指出在“ent.payment_id)*0.50”之后发现了一个意外的令牌“END-OF-STATEMENT”。预期的标记可能包括:“”。行号=6。 SQLSTATE=42601

标签: stored-procedures db2


【解决方案1】:

在你的程序中试试这个

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') 

【讨论】:

    【解决方案2】:

    尝试将上面的代码放入您的代码中:

    "--"

    将“end@”替换为“end;”

    【讨论】:

    • --
    猜你喜欢
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 2019-02-02
    • 2017-05-25
    • 1970-01-01
    • 2020-07-06
    相关资源
    最近更新 更多