【发布时间】:2020-01-22 20:43:18
【问题描述】:
我试图向表中插入一些示例数据,但 db2 命令行处理器返回此消息“DB21034E 该命令被作为 SQL 语句处理,因为它不是
有效的命令行处理器命令。在 SQL 处理期间,它返回:
SQL0723N 触发器中的触发 SQL 语句发生错误
“埃德温.CALLCQ”。错误返回的信息包括SQLCODE "-724",
SQLSTATE "54038" 和消息令牌“EDWIN.CHKQUANTITY|PROCEDURE”。
SQLSTATE=09000"
这是我的程序
create procedure chkQuantity (Cart_ID int,Food_ID int, Food_Quantity int)begin declare c cursor with return for select sum(Food_Quantity) from Cart_details group by Cart_ID;open c; If(Food_Quantity <= 10)then insert into cart_details(Cart_ID,Food_ID,Food_Quantity) values (Cart_ID , Food_ID ,Food_Quantity);Else signal sqlstate'45000' set message_text = '1 Cart Maximum order only 10 food Quantity' ;delete from cart_details where cart_details_id=cart_details_id; end if;close c; end
触发
create trigger callCQ after insert on cart_details referencing new as N for each row mode db2sql call chkQuantity(N.Cart_ID, N.Food_ID, N.Food_Quantity)
表格
create table Cart_Details(Cart_Details_ID int not null primary key ,Cart_ID int , Foreign Key(Cart_ID) references Cart,Food_ID int,foreign key(Food_ID) references Food, Food_quantity int check(food_quantity <= 10))
【问题讨论】:
-
包含实际的错误消息而不是只包含错误代码会很有用。
-
至于你的程序逻辑。您应该注意以下事项。使用没有
fetch的游标是没有用的:你不能只使用打开/关闭语句的结果。您使用delete from cart_details where cart_details_id=cart_details_id语句删除表中的所有行,因为如果您的列名和参数名相同,那么这样的名称将被视为列名。
标签: db2 db2-express-c