我想通过使用命令获取用于创建现有过程的代码
show create procedure
然后将它存储在一个变量中。所有这些都在一个过程中。
问题
Set @var
用于创建用户定义的变量仅在结果包含一行和一列时有效。show create procedure proc_name
返回多个列,我无法选择特定的列Create Function
问题
如何将创建过程的代码保存到变量中供以后使用。
最佳答案
您可以使用 information_schema 数据库中的例程表。
select
routine_definition
from
information_schema.routines
where
specific_name = 'nameOfYourStoredProcedure'
有关更多信息,请参阅此 link.
更新:
然后您将不得不自己构建它。没有其他办法。
select
CONCAT('CREATE PROCEDURE nameOfYourStoredProcedure ', routine_definition, 'END') /*something like that, this here is pseudo-code*/
from
information_schema.routines
where
specific_name = 'nameOfYourStoredProcedure'
更新 2:
考虑到 Devart 的评论,您还必须使用 information_schema 数据库中的参数表。
注:此表是MySQL 5.5.3新增的
有关更多信息,请查看 here.
老实说,我不知道还有什么其他方法可以解决这个问题。另外我不能在这里更新到 5.5.3 来帮助你。祝你好运。
关于mysql - 将 `show create procedure procedure_name` 的结果存储到 MySql 中的一个变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10121006/