我想写一个这样的程序:
CREATE PROCEDURE `addByType`(IN myDate DATETIME, IN myType INT, OUT output DATETIME)
BEGIN
DECLARE unit ?;
CASE
WHEN myType = 1 THEN
SET unit = HOUR;
WHEN myType = 2 THEN
SET unit = DAY;
...
END CASE;
SELECT TIMESTAMPADD(unit, 1, myDate) INTO output;
END
有可能吗?我可以将单位关键字存储到变量中吗?或者还有其他方法可以达到同样的效果吗?