mysql存储过程中执行事务

2018-10-12  本文已影响8人  蜗牛_96f2

CREATE PROCEDURE `test`(

IN id int(10)

)

BEGIN

DECLARE t_error INTEGER DEFAULT 0;

    DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1;

        START TRANSACTION;

            insert into bbs(title, context,type) values('a','b',0);

    insert into bbs(title, context,type) values('a','b',0);

    insert into bbs(title, context,type) values('a','b',0);

    insert into bbs(title, context,type) values('a','b',0);

    insert into bbs(title, context,type) values('a','b',0);

    insert into bbs(title, context,type) values('a','b',0);

    insert into bbs(title, context,type) values('a','b',0);

    insert into bbs(title, context,typedd) values('a','b',0);

        IF t_error = 1 THEN

            ROLLBACK;

        ELSE

            COMMIT;

        END IF;

    select t_error;

END

上一篇下一篇

猜你喜欢

热点阅读