문제

MySQL stored procedure will throw the error out if there is no rollback command for SQLEXCEPTION, but it has changed some data before the exception.
I add rollback command for SQL exceptions:

DECLARE EXIT HANDLER FOR SQLEXCEPTION 
BEGIN
    ROLLBACK; 
END;

But I can not know the reason of the rollback now.
I know we can define every SQL exception and it's handler, but it's too complex and I just want to know why the rollback occurred.
Is there a simple method to get the reason of rollback in MySQL stored procedure?

도움이 되었습니까?

해결책

Thanks @kordirko. I have get one solution with RESIGNAL. But it is only supported until MySQL 5.5.

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
  SET @flag = 1;
  IF @flag = 1 THEN RESIGNAL;END IF;
  ROLLBACK;
END;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top