大家好,
我在做SqlServer向MySql的数据库迁移,其中有一个存储过程pre_Sys_Get_Data,接受业务ID及访问参数,过程中根据业务ID,从业务定义表中,获取对应的过程过程名称,再把这个过程名称和输入的参数拼接一个新的Sql语句,并动态执行,这时,报错:
Error Code: 1444. The prepared statement contains a stored routine call that refers to that same statement. It's not allowed to execute a prepared statement in such a recursive manner
请问有什么办法解决呢,谢谢。
CREATE DEFINER=`sameCityDeliverUser`@`%` PROCEDURE `pre_Sys_Get_Data`(
_menuFunID CHAR(32),
_selectCount BIT,
_treeAutoExpand bit,
_findWhere VARCHAR(2000),
_orderBy VARCHAR(2000)
)
BEGIN
DECLARE _sSql VARCHAR(2000);
DECLARE _iFunType INT;
DECLARE _sExecSql VARCHAR(2000);
declare var_selectCount varchar(5);
declare var_treeAutoExpand varchar(5);
if _selectCount is Null then
set _selectCount=true;
end if;
if _treeAutoExpand is Null then
set _treeAutoExpand=true;
end if;
set var_selectCount='false';
set var_treeAutoExpand='false';
if _selectCount then
set var_selectCount='true';
end if;
if _treeAutoExpand then
set var_treeAutoExpand='true';
end if;
SET _sSql = '';
IF EXISTS (SELECT 1 FROM T_Menu_Get_Data WHERE id = _menuFunID) then
SELECT funSql,
funType into _sSql,_iFunType
FROM T_Menu_Get_Data
WHERE id = _menuFunID;
end if;
IF _iFunType = 1 then
SELECT '不能执行系统查询方法';
elseif _sSql <> '' then
SET _sExecSql = concat(_sSql, '(',var_selectCount,',',var_treeAutoExpand,
',' , IFNULL(_findWhere, '') ,
CASE WHEN IFNULL(_orderBy,'')='' THEN '' ELSE concat(',',_orderBy) END,')');
set @sql = _sExecSql;
PREPARE s1 from @sql;
EXECUTE s1;
deallocate prepare s1;
ELSE
SELECT '没有找到执行的方法';
end if;
END
调用方法:
CALL pre_Sys_Get_Data('6D01977D469047CB9914E5DA9820EF59',0,1,'\' where ifNull(_parentId,\'\'\'\') = \'\'\'\' \'','\' order by sortorder asc\'')