문제

I'm using mysql v5.1.48 and red http://dev.mysql.com/doc/refman/5.5/en/signal.html. But the code

DELIMITER $$
CREATE PROCEDURE `CoreRaiseError`()
BEGIN
  SIGNAL SQLSTATE '45000'
      SET MESSAGE_TEXT = 'An error occurred', MYSQL_ERRNO = 1001;
END$$

raise an

SQL Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SQLSTATE '45000'

From which version SIGNAL start to be a keyword? How can I raise an exception with prior version of mysql?

Thank you.

도움이 되었습니까?

해결책

As stated in the manual for MySQL version 5.1:

Other statements related to conditions are SIGNAL, RESIGNAL, and GET DIAGNOSTICS. The SIGNAL and RESIGNAL statements are not supported until MySQL 5.5. The GET DIAGNOSTICS statement is not supported until MySQL 5.6.

To raise an error in older versions of MySQL, just deliberately issue an erroneous command. I often CALL a non-existent procedure, for example:

CALL raise_error;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top