我想将存储过程转换为mysql sp?

时间:2013-01-18 09:02:57

标签: mysql stored-procedures

CREATE PROCEDURE [dbo].[TR_PROC_UpdateRelMgrByHrID]
(
    @REF_DIV_ID Int,
    @STAFFIDS varchar(500)
)
AS
BEGIN
    BEGIN TRAN
--  DECLARE @STAFFIDS varchar(8000)
--  SET @STAFFIDS = '2,19,14'
    DECLARE @temptable TABLE (items int)       
    INSERT INTO @temptable 
    VALUES(@REF_DIV_ID)
    DELETE FROM Tbl_RelationshipMgr
    WHERE IntHRID = @REF_DIV_ID
    INSERT INTO Tbl_RelationshipMgr(IntStaffID,IntHRID)
    SELECT * from dbo.Split(@STAFFIDS, ','), @temptable 
    COMMIT
END

1 个答案:

答案 0 :(得分:1)

在MySQL中你的sp可以写成: -

DELIMITER $$


CREATE PROCEDURE TR_PROC_UpdateRelMgrByHrID
(
    REF_DIV_ID INT(11)

)
BEGIN
    START TRANSACTION;

    INSERT INTO items VALUES (REF_DIV_ID);

    DELETE FROM Tbl_RelationshipMgr WHERE IntHRID = REF_DIV_ID;

    INSERT INTO Tbl_RelationshipMgr(`IntStaffID`,`IntHRID`) SELECT * from items ;

    COMMIT;
END$$

DELIMITER ;

您可能希望根据需要更改查询。