我希望动态sql在mysql中创建存储过程。例如:存储过程从动态sql创建存储过程
delimiter ///
create procedure x1()
begin
set @sql = '
drop procedure if exists x2;
delimiter ///
create procedure x2()
begin
INSERT INTO `world`.`city`
(`Name`,
`CountryCode`,
`District`,
`Population`)
VALUES
(''Meyerton'',
''ZAR'',
''Africa'',
500);
end ///
delimiter ;
call x2();
drop procedure if exists x2;';
prepare stmt1 from @sql;
execute stmt1;
deallocate prepare stmt1;
end ///
delimiter ;
call x1();
,但是当过我打电话的过程x1
我收到以下错误Error Code: 1064. 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 'DELIMITER /// CREATE PROCEDURE 20140416_TriggerSP_NoUserFound() BEGIN DECLARE ' at line 3
这是从SQL代码的实际触发。上面的sql代码是实际sql代码的一个非常简化的版本。
所以问题是,动态sql在存储过程中可以在mysql中创建存储过程吗? 如果需要,请加载原始SQL。
只是为了让你知道,stackoverflow的目标(虽然它似乎并不如此乍一看)是,某种类型的维基。因此,包括事实在内的答案将受到赞赏,包括来源。 – fancyPants
对不起,我现在意识到我的答案有点模糊,而且信息量不大 –