如何在MySql过程中引发错误? [英] How to throw an error in MySql procedure?

查看:86
本文介绍了如何在MySql过程中引发错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是强制MySQL在存储过程内引发错误的机制?

What is the mechanism to force the MySQL to throw an error within the stored procedure?

我有一个调用另一个函数的过程:

I have a procedure which call s another function:

PREPARE my_cmd FROM @jobcommand;
EXECUTE my_cmd;
DEALLOCATE PREPARE my_cmd;

job命令是:

jobq.exec("Select 1;wfdlk# to simulatte an error");

然后:

CREATE PROCEDURE jobq.`exec`(jobID VARCHAR(128),cmd TEXT)
BEGIN
DECLARE result INT DEFAULT 0;  
SELECT sys_exec( CONCAT('echo ',cmd,' |  base64 -d > ', '/tmp/jobq.',jobID,'.sh ; bash /tmp/jobq.',jobID,'.sh &> /tmp/jobq.',jobID)) INTO result; 
IF result>0 THEN 
# call raise_mysql_error(result); 
END IF;
END;

我的作业q.exec总是成功的. 有没有办法引发错误? 如何实现raise_mysql_error函数?

My jobq.exec is always succeeding. Are there way to rise an error? How to implement raise_mysql_error function??

顺便说一句,我正在使用MySQL 5.5.8

BTW I am using MySQL 5.5.8

感谢阿尔曼.

推荐答案

是的,有:使用

Yes, there is: use the SIGNAL keyword.

这篇关于如何在MySql过程中引发错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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