Myślę, że problem polega na tym, że nie używasz DELIMITER
.
Więc po prostu ujmij to w ten sposób:
DELIMITER //
create procedure AddColumnUnlessExists(
IN dbName tinytext,
IN tableName tinytext,
IN fieldName tinytext,
IN fieldDef text)
begin
IF NOT EXISTS (
SELECT * FROM information_schema.COLUMNS
WHERE column_name=fieldName
and table_name=tableName
and table_schema=dbName
)
THEN
set @ddl = CONCAT('ALTER TABLE ', dbName, '.', tableName, ' ADD COLUMN ', fieldName, ' ', fieldDef);
prepare stmt from @ddl;
execute stmt;
END IF;
end //
DELIMITER ;
EDYTUJ https://dev.mysql.com/doc /refman/5.7/en/stored-programs-defining.html