Can I use prepare statement to create function and stored procedures in mysql?

60 Views Asked by At

I need to create a new function and stored procedures through the prepare and execute statement. Whether it is possible or not?

prepare statement from 'DELIMITER ;;
CREATE FUNCTION `db_name`.`fn_name`(Params)
RETURNS varchar(50) CHARSET utf8mb4 DETERMINISTIC
BEGIN
DECLARE name varchar(50);
RETURN IFNULL(name,"");
END ;;
DELIMITER ;';
execute statement;
1

There are 1 best solutions below

0
Barmar On

No, it's not possible. See SQL Syntax Permitted in Prepared Statements for the list of statements allowed in prepared statements. CREATE PROCEDURE isn't one of them.