MySQL : transaction within a stored procedure

后端 未结 4 793
离开以前
离开以前 2020-11-27 13:13

The basic structure of my stored procedure is,

BEGIN

    .. Declare statements ..

    START TRANSACTION;

        .. Query 1 ..
        .. Query 2 ..
              


        
4条回答
  •  Happy的楠姐
    2020-11-27 13:40

    Just an alternative to the code by rkosegi,

    BEGIN
    
        .. Declare statements ..
    
        DECLARE EXIT HANDLER FOR SQLEXCEPTION 
        BEGIN
              .. set any flags etc  eg. SET @flag = 0; ..
              ROLLBACK;
        END;
    
        START TRANSACTION;
    
            .. Query 1 ..
            .. Query 2 ..
            .. Query 3 ..
    
        COMMIT;
        .. eg. SET @flag = 1; ..
    
    END
    

提交回复
热议问题