如何在MySql过程中抛出错误?
强制MySQL在存储过程中抛出错误的机制是什么?
我有一个调用另一个函数的过程:
PREPARE my_cmd FROM @jobcommand;
EXECUTE my_cmd;
DEALLOCATE PREPARE my_cmd;
作业命令是:
jobq.exec("Select 1;wfdlk# to simulatte an error");
then:
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;
我的 jobq.exec
总是成功。 有办法提高错误吗? 如何实现raise_mysql_error函数?
我使用的是 MySQL 5.5.8
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;
the job command is:
jobq.exec("Select 1;wfdlk# to simulatte an error");
then:
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;
My jobq.exec
is always succeeding.
Are there way to rise an error?
How to implement raise_mysql_error function??
I am using MySQL 5.5.8
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,有:使用
SIGNAL
< /a> 关键字。Yes, there is: use the
SIGNAL
keyword.您可以使用以下存储过程来模拟错误抛出:
示例:
You may use following stored procedure to emulate error-throwing:
Example: