I would like to know if it's possible to pass a parameter to a mysql stored procedure and use this parameter as the unit parameter of the DATE_SUB function. It seems that the unit parameter is a reserved word so I don't know if there's a type for unit.
Exemple of what I'm trying to do :
DELIMITER $$
DROP PROCEDURE IF EXISTS `test` $$
CREATE DEFINER=`root`@`%` PROCEDURE `test`(param1 unit)
BEGIN
select DATE_SUB(now(), INTERVAL 1 param1);
END $$
DELIMITER ;
UPDATE 1 I tried with a prepare statement, I'm able to create the stored proc.
DELIMITER $$
DROP PROCEDURE IF EXISTS `test` $$
CREATE DEFINER=`root`@`%` PROCEDURE `test`(param1 varchar(10))
BEGIN
PREPARE stmt FROM 'SELECT DATE_SUB(now(), INTERVAL 1 ?)';
EXECUTE stmt USING @param1;
END $$
DELIMITER ;
When I executed it : CALL test('WEEK'); 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 '?)' at line 1