我有两个表:item_group 和 item_breakdown。我想同时填写两个表,所以我决定使用存储过程。这是我到目前为止创建的内容,但出现错误。我还是 phpmyadmin 的新手,我的英语不是那么好,所以请多多包涵:)
CREATE PROCEDURE sp_test5
(
IN item_group_desc varchar(150),
IN item_group_qty int(5),
IN item_group_uom varchar(10),
IN item_group_location varchar(50),
IN item_group_inv_by varchar(50),
IN item_group_crit_amount int(5)
)
BEGIN
INSERT INTO item_group(item_group_code,item_group_desc,categ_ID,item_group_qty,uom,location,inv_by,type,name,desc,sci_name,crit_amount)
VALUES ('asd',item_group_desc,1,item_group_qty,item_group_uom,item_group_location,item_group_inv_by,'n/a','n/a','n/a','n/a',item_group_crit_amount);
declare x int;
set x=1;
while x<=item_group_qty do
INSERT INTO item_breakdown(status,brand,expiry,item_group_ID)
VALUES(
SELECT
'available',
'n/a',
'n/a',
item_group_id
FROM item_group
ORDER BY item_group_id DESC
LIMIT 1 ***plus 1
);
set x=x+1;
END WHILE
END//
我把“加 1”放在那里,因为 item_group_code 是 Auto_increment,我想使用下一个值插入第二个表。谁能帮助我并指出我做错了什么?先感谢您