我正在尝试将存储过程从 SQL Server 迁移到 MySQL。我在转换 try catch block 时遇到了一些问题。我知道 DECLARE HANDLER
可以用来代替 MySQL 中的 TRY
/CATCH
block 。如何使用 DECLARE HANDLER
在 MySQL 存储过程中复制此 CATCH
语句的功能?
BEGIN CATCH
CLOSE transDetails //cursor name
CLOSE transQuoteOptionDetails//another cursor name
DEALLOCATE transDetails
DEALLOCATE transQuoteOptionDetails
DECLARE @ErrorMessage varchar(2000),@ErrorSeverity tinyint,@ErrorState tinyint
SET @ErrorMessage = ERROR_MESSAGE()
SET @ErrorSeverity = ERROR_SEVERITY()
SET @ErrorState = ERROR_STATE()
Delete From MasterReport_Temp where masterReportRecNo=@masterReportRecNo
Update MasterReport set status=3, errorDescription=@ErrorMessage where recNo=@masterReportRecNo
END CATCH
最佳答案
似乎在 mysql 中没有 try catch 等价物
但是有一种方法可以使用 SIGNAL 处理错误
SIGNAL is the way to “return” an error. SIGNAL provides error information to a handler, to an outer portion of the application, or to the client. Also, it provides control over the error's characteristics (error number, SQLSTATE value, message). Without SIGNAL, it is necessary to resort to workarounds such as deliberately referring to a nonexistent table to cause a routine to return an error.
关于mysql - sql server try catch block 的mysql等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34409183/