请看源码:
-- 创建表 DROP TABLE IF EXISTS test; CREATE TABLE test ( `t_A` varchar(20) NOT NULL, `t_B` varchar(20) DEFAULT NULL, `t_C` varchar(20) DEFAULT NULL, `t_D` varchar(20) DEFAULT NULL, PRIMARY KEY (`t_A`) ); -- 创建存储过程 DROP PROCEDURE IF EXISTS p_test_a; CREATE PROCEDURE p_test_a (i_a VARCHAR(20), i_b VARCHAR(20)) BEGIN DECLARE v_b VARCHAR(20); SET v_b="b4"; IF v_a="1" THEN BEGIN UPDATE test SET t_A="a4" WHERE t_B=v_b; END; ELSE BEGIN INSERT INTO test VALUES ("a5","b5","c5","d5"); END; END IF; BEGIN INSERT INTO test VALUES ("a6","b6","c6","d6"); END; IF i_b="1" THEN BEGIN UPDATE test SET t_A="a4" WHERE t_B=v_b; END; ELSE BEGIN INSERT INTO test VALUES ("a7","b7","c7","d7"); END; END IF; END;
创建p_test_a 就会报错,但是假如把后面的 IF i_b=”1″ THEN 去掉 就不报错
DROP PROCEDURE IF EXISTS p_test_a; CREATE PROCEDURE p_test_a (i_a VARCHAR(20), i_b VARCHAR(20)) BEGIN DECLARE v_b VARCHAR(20); SET v_b="b4"; IF v_a="1" THEN BEGIN UPDATE test SET t_A="a4" WHERE t_B=v_b; END; ELSE BEGIN INSERT INTO test VALUES ("a5","b5","c5","d5"); END; END IF; BEGIN INSERT INTO test VALUES ("a6","b6","c6","d6"); END; -- IF i_b="1" THEN BEGIN UPDATE test SET t_A="a4" WHERE t_B=v_b; END; -- ELSE BEGIN INSERT INTO test VALUES ("a7","b7","c7","d7"); END; -- END IF; END;
高手帮忙解答下吧,为啥?
解决方案
40
错误提示是什么?