數據庫 - Mysql的存儲過程真的是個坑!求助下面的存儲過程哪里錯啦,實在是找不到哪里的問題了。
問題描述
BEGIN
declare step1,step2 varchar(50);declare p_tar_code varchar(10);DECLARE p_tYear,p_period int;DECLARE p_centAll,p_up_comCent decimal(5,2);-- 1:獲取當前年度和季度select period,tyear into p_period,p_tYear from tm_checkmain where id = 95 LIMIT 1;-- 2:如果季度是1,則上年得分為0,否則要計算 if period = 21 then set p_up_comCent = 0; end if
select tar_code into p_tar_code from tm_checkdetails where id = 95 LIMIT 1;
set str = p_tar_code;
END
將IF判斷注釋掉,則通過,否則則報錯。
One or more errors have occurred while processing your request:下列查詢失敗了: 'CREATE DEFINER=root@localhost PROCEDURE comCent(IN cm_id INT(11) UNSIGNED, OUT str VARCHAR(10)) NO SQL SQL SECURITY DEFINER BEGIN declare step1,step2 varchar(50); declare p_tar_code varchar(10); DECLARE p_tYear,p_period int; DECLARE p_centAll,p_up_comCent decimal(5,2); -- 1:獲取當前年度和季度 select period,tyear into p_period,p_tYear from tm_checkmain where id = 95 LIMIT 1; -- 2:如果季度是1,則上年得分為0,否則要計算 if period = 21 then set p_up_comCent = 0; end if -- select tar_code into p_tar_code from tm_checkdetails where id = 95 LIMIT 1; -- set step2 = ’如果是月則返回’; -- set str = p_tar_code; END'MySQL 返回: #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 ’END’ at line 22
請教高手,IF判斷根本沒有錯誤呀。
問題解答
回答1:end if差個分號