标签:
BEGIN DECLARE result INTEGER DEFAULT 0; -- 标记是否出错 DECLARE t_error INTEGER DEFAULT 0; -- 如果出现sql异常,则将t_error设置为1后继续执行后面的操作 DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET t_error=1; -- 显示的开启事务,启动它后,autocommit值会自动设置为0 START TRANSACTION; INSERT into shop_invoicerecords (ordersjson,orderIdjson,totalmoney,sourcedomain,userId ,invoicejson,auditingstate ,invoiceAddrssjson,addDate )VALUES(_ordersjson,_orderIdjson,_totalmoney,_sourcedomain,_userId,_invoicejson,_auditingstate,_invoiceAddrssjson,_addDate ); UPDATE shop_order set paymenttype=_paymentType where sourcedomain=_sourcedomain and FIND_IN_SET(id,_orderId); -- 标记被改变,表示事务应该回滚 IF t_error=1 THEN -- 事务回滚 ROLLBACK; set result=-1; ELSE -- 事务提交 COMMIT; set result=1; END IF; SELECT result; END
标签:
原文地址:http://www.cnblogs.com/xiaoyaodijun/p/4425732.html