如何获取MySQL 5.5中存储过程的异常消息 [英] How to get exception message on stored procedure in MySQL 5.5

查看:437
本文介绍了如何获取MySQL 5.5中存储过程的异常消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MySQL 5.5。
要在MySQL 5.6上获取异常消息是使用 GET DIAGNOSTIC 函数。 MySQL 5.5中有类似的功能吗?
我正在工作的项目已经使用MySQL 5.5版。

解决方案

p>您可以尝试使用 SHOW ERROR SHOW WARNING 。要查看最后一个错误或警告,您可以使用它作为:

  SHOW ERRORS LIMIT 1  - 对于SQL状态> 2 
SHOW WARNINGS LIMIT 1 - 对于SQL状态1,2

为了阻止列出每一个错误,您可以处理一类SQL错误,如下所示:


SQLWARNING是SQLSTATE类的简写$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

$ p $ NOT $这仅在游标的上下文中是有关的,并且
用于控制当光标到达数据
集合的结尾时会发生什么。如果没有更多的行可用,则
SQLSTATE值为02000时将发生无数据条件。要检测此条件,您可以为其设置
处理程序(或者为非FOUND条件)。一个例子显示在
第12.7.5节游标中。此条件也适用于SELECT ...
INTO var_list语句,用于检索任何行。



SQLEXCEPTION是不为$ b的SQLSTATE值类的缩写$ b以'00','01'或'02'开头。


为了处理异常,你只需要做:

  SQLSTATE SQLEXCEPTION的DECLARE退出处理程序.....; 

链接



http://dev.mysql.com/doc/refman/ 5.5 / en / signal.html



http://dev.mysql.com/doc/refman/5.0/en/declare-handler.html


I'm using MySQL 5.5.
To get the exception message on MySQL 5.6 is using GET DIAGNOSTIC function. Is there any similar function in MySQL 5.5 ,.?
The project I'm working is already use MySQL version 5.5.

解决方案

You could try using SHOW ERROR and SHOW WARNING. To see the last error or warning you could use it as:

SHOW ERRORS LIMIT 1   -- for SQL-state > 2
SHOW WARNINGS LIMIT 1 -- for SQL-state 1,2

In order to prevent listing each and every error, you can handle a class of SQL-errors like so:

SQLWARNING is shorthand for the class of SQLSTATE values that begin with '01'.

NOT FOUND is shorthand for the class of SQLSTATE values that begin with '02'. This is relevant only within the context of cursors and is used to control what happens when a cursor reaches the end of a data set. If no more rows are available, a No Data condition occurs with SQLSTATE value 02000. To detect this condition, you can set up a handler for it (or for a NOT FOUND condition). An example is shown in Section 12.7.5, "Cursors". This condition also occurs for SELECT ... INTO var_list statements that retrieve no rows.

SQLEXCEPTION is shorthand for the class of SQLSTATE values that do not begin with '00', '01', or '02'.

So to handle an exception, you need to only do:

DECLARE EXIT HANDLER FOR SQLSTATE SQLEXCEPTION .....;

Links:

http://dev.mysql.com/doc/refman/5.5/en/signal.html

http://dev.mysql.com/doc/refman/5.0/en/declare-handler.html

这篇关于如何获取MySQL 5.5中存储过程的异常消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆