How to throw an error in MySql procedure?

后端 未结 2 703
生来不讨喜
生来不讨喜 2020-12-20 13:35

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_         


        
相关标签:
2条回答
  • 2020-12-20 13:37

    Yes, there is: use the SIGNAL keyword.

    0 讨论(0)
  • 2020-12-20 13:45

    You may use following stored procedure to emulate error-throwing:

    CREATE PROCEDURE `raise`(`errno` BIGINT UNSIGNED, `message` VARCHAR(256))
    BEGIN
    SIGNAL SQLSTATE
        'ERR0R'
    SET
        MESSAGE_TEXT = `message`,
        MYSQL_ERRNO = `errno`;
    END
    

    Example:

    CALL `raise`(1356, 'My Error Message');
    
    0 讨论(0)
提交回复
热议问题