可以使用预处理语句在MySQL中创建函数和存储过程吗?

huangapple go评论66阅读模式
英文:

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

问题

我需要通过准备和执行语句来创建一个新的函数和存储过程。是否可能?

准备语句如下:

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

执行语句。

英文:

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

得分: 2

不,这是不可能的。请参考准备语句中允许的 SQL 语法,了解准备语句中允许的语句列表。CREATE PROCEDURE 不在其中。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月27日 14:28:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76777014.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定