MySQL 返回存储过程抛出的确切错误/警告

标签 mysql exception

这是我第一次使用Mysql SP。我有一个过程可以执行多个 DML 操作,如插入和更新。但它有时会发出警告。我想在执行脚本时显示确切的警告(在 shell/控制台上)。目前,当发生异常时,我会得到类似下面的信息。

Query OK, 0 rows affected, 1 warning (0.08 sec)

当我使用 workbench 等 mysql 客户端执行相同的过程并执行该过程时。我收到一条正确的错误消息。这就是我想要在控制台上打印的内容。

1   10:33:03    call dbscripts(@param)  0 row(s) affected, 1 warning(s): 1062 Duplicate entry '124' for key 'PRIMARY'

我该怎么做?

谢谢

最佳答案

您可以使用SHOW WARNINGS。来自documentation :

SHOW WARNINGS shows information about the conditions (errors, warnings, and notes) that resulted from the last statement in the current session that generated messages.

关于MySQL 返回存储过程抛出的确切错误/警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14744225/

相关文章:

java - 防止用户输入大于 int max 的值?

c++ - Noexcept 对派生类构造函数的 promise : can that be used without promising noexcept on base constructor?

mysql - 站点迁移后建立数据库连接时出错?

mysql - HTML 在图像的特定位置显示文本

php - 带负数的日期时间格式问题

ruby-on-rails - AirBrake vs Exceptional vs errbit : which one is the best to track exceptions in your rails app?

asp.net - 如何从异常中获取更多详细信息?

jsp - 将异常从 servlet 转发到 jsp 页面的好方法是什么?

mysql - 错误 "mysql could not fetch schema table status"

php - MySQL正则表达式替换?