2017-01-15 59 views
-1
create table tbl_order_detail(
o_detail_id int NOT NULL AUTO_INCREMENT, 
o_id int NOT NULL, 
p_id int NOT NULL, 
user_qty int NOT NULL, 
total int NOT NULL, 
primary key(o_detail_id), 
foreign key(o_id) references tbl_order(o_id),**strong text** 
foreign key(p_id) references tbl_product(p_id)); 

------------------------------------------------------------------------------ 

create procedure user_buy_item1(o_id int,pid int,user_qty int,total int) 
begin 
DECLARE total_products INT DEFAULT 0; 
DECLARE new_total INT DEFAULT 0; 
insert into tbl_order_detail values(null,o_id,pid,user_qty,total); 
select p_qty into total_products from tbl_product where p_id = pid; 
set new_total = total_products - user_qty; 
update tbl_product set p_qty = new_total where p_id = pid; 
end 

錯誤 SQL查詢:在我的phpmyadmin當我使用這個程序我得到這個SQL錯誤

create procedure user_buy_item1(o_id int,pid int,user_qty int,total int) 
begin 
DECLARE total_products INT DEFAULT 0 
MySQL said: Documentation 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 3 ** 
+1

插入NUL值o_detail_id不爲空 –

+0

創建過程時,您使用了不同的分隔符嗎? –

+0

不建議在不指定列列表的情況下使用'insert into'。 – halfer

回答

0

試試這個改變你的插入查詢

insert into tbl_order_detail(o_id,p_id , user_qty, total) values(o_id,pid,user_qty,total); 
相關問題