简体   繁体   English

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

[英]MySQL return exact error/warning that stored procedure throws

This is my first time with Mysql SP. 这是我第一次使用Mysql SP。 I've a procedure that does several DML operations like inserts and updates. 我有一个执行一些DML操作(如插入和更新)的过程。 But it sometimes throws a warning. 但这有时会发出警告。 I want to show that exact warning as it is(on shell/console) when the script is executed. 我想显示执行脚本时的确切警告(在外壳/控制台上)。 Currently, I get something like below when an exception occurs. 当前,发生异常时,我得到类似下面的信息。

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

When I execute the same procedure using a mysql client like workbench and execute the procedure. 当我使用像工作台之类的mysql客户端执行相同的过程并执行该过程时。 I get a proper error message. 我收到正确的错误消息。 This is what I want printed on console. 这就是我要在控制台上打印的内容。

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

How can I do this? 我怎样才能做到这一点?

Thanks 谢谢

You can use SHOW WARNINGS . 您可以使用SHOW WARNINGS From the 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. SHOW WARNINGS显示有关当前会话中最后一条生成消息的语句所导致的条件(错误,警告和注释)的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM