MySQL server version for the right syntax to use near 'IF'
MySQL server version for the right syntax to use near ''
MySQL server version for the right syntax to use near 'END IF'
MySQL server version for the right syntax to use near 'END'
语法没问题,但执行时报莫名其妙错误时,分隔符的问题,mysql默认的分隔符为“;”,而“FROM table_name”后是“;”,mysql默认SQL语句结束,所以出错。
解决方法:要加上 DELIMITER // .... //
DELIMITER // CREATE PROCEDURE mes.ADD_USER_REAL_NAME() BEGIN IF NOT EXISTS (SELECT * FROM information_schema.COLUMNS WHERE table_schema = 'test' AND table_name = 'sys_user' AND column_name = 'REAL_NAME') THEN ALTER TABLE `sys_user` ADD COLUMN `REAL_NAME` VARCHAR(20) NULL COMMENT '真实姓名' AFTER `LoginName`; END IF; END; //