本人在navicat 里 使用sql生成的存储过程 代码如下
BEGIN DECLARE iCount INT DEFAULT 0; DROP TABLE IF EXISTS avg_prices; create table avg_prices as select goods_id,goods_type,goods_name,in_buy_price,ROUND(sum(in_total_price)/sum(in_amount),2) as "junjia",NOW(),count(*) from scm.in_warehouse_detail group by goods_id,goods_type,goods_name order by goods_id,goods_type,goods_name; select count(*) into iCount from goods g,avg_prices a where g.goods_Id = a.goods_id and g.goods_sel_price != a.junjia and g.goods_buy_price != a.junjia; if iCount > 0 then update avg_prices a,goods g set g.goods_buy_price = a.junjia where g.goods_Id = a.goods_id and g.goods_sel_price != a.junjia ; else end if; END;
运行报错:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near " DECLARE iCount INT DEFAULT 0" at line 2
解决方案
10
delimiter //
create procedure …
begin
…
end
//
delimiter ;
create procedure …
begin
…
end
//
delimiter ;
10
else
end if
是什么? 去掉else
end if
是什么? 去掉else