Mycat下执行存储过程,参数IN、OUT

1.无参数

使用CREAT PROCEDURE,会同时在其他分片数据库创建存储过程

原存储过程

DROP PROCEDURE IF EXISTS `SP_DeleteFailureRecord`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_DeleteFailureRecord`()
BEGIN
delete from t_wlkx where f_ParentID IN
(SELECT f_ParentID from t_wlkx_up where f_Progress > 0 and f_Progress < 100);
UPDATE t_wlkx SET f_MdlID = NULL WHERE f_ID IN
(SELECT f_ParentID from t_wlkx_up where f_Progress > 0 and f_Progress < 100);
END
;;
DELIMITER ;

Mycat下创建存储过程:

/*!mycat: sql=delete from t_wlkx where f_ParentID IN
(SELECT f_ParentID from t_wlkx_up where f_Progress > 0 and f_Progress < 100);
UPDATE t_wlkx SET f_MdlID = NULL WHERE f_ID IN
(SELECT f_ParentID from t_wlkx_up where f_Progress > 0 and f_Progress < 100);*/ CALL `SP_DeleteFailureRecord`();

2.有参数 IN 、OUT

使用set,需要先在分片数据库执行存储过程,再到mycat中执行

原存储过程

DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_InsertWlkx`(MdlID bigint, ParentID bigint, Name char(255),out NewID bigint)
BEGIN
IF MdlID = -1 THEN
	INSERT INTO t_wlkx(f_ParentID, f_Name) values(ParentID, Name );
ELSE
	INSERT INTO t_wlkx(f_MdlId, f_ParentID, f_Name) values(MdlID , ParentID, Name );
END IF;
SELECT @@Identity into NewID;
END
;;
DELIMITER ;

Mycat下创建存储过程

/*!mycat: sql=IF MdlID = -1 THEN 
	INSERT INTO t_wlkx(f_ParentID, f_Name) values(ParentID, Name );
ELSE 
	INSERT INTO t_wlkx(f_MdlId, f_ParentID, f_Name) values(MdlID , ParentID, Name );
END IF;
SELECT @@Identity into NewID;*/set @MdlID=null,@ParentID=null,@Name=null;call SP_InsertWlkx(@MdlID,@ParentID,@Name,@NewID);select @NewID

 

你可能感兴趣的:(数据库,Mycat)