MySQL exception handler scope and priority

Source: Internet
Author: User

Scope:

 

1. Include the statements in begni... end;

Declare continue handler for 1048 SELECT 'attempt to insert a null value ';
BEGIN
Insert into a VALUES (6, NULL );
END;
If the second field of Table a is not empty, the 1048 error is triggered. 2. If the error processing is defined in begin... end, other statements will not trigger the error.BEGIN
BEGIN
Declare continue handler for 1216 select
'Foreign key constraint violated ';
END;
Insert into orders ments (department_name, manager_id, location)
VALUES ('elbonian hr', 'catbert ', 'catbertia ');
END;
3. capture errors thrown by other stored procedures

 

Priority:

 

You can define multiple handler in a begin... end block to handle different exceptions respectively. For example:

Declare exit handler for sqlexception
Begin
Select 'error ';
End;

DECLARE continue handler for sqlstate '000000' SET done = 1;

The processing priority is:

MySQL Error code> SQLSTATE code> naming ConditionsMySQL error code, for example 1062
ANSI standard SQLSTATE code, for example 23000
Naming conditions, such as NOT FOUND

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.