[Original] added SIGNAL Exception Handling in MySQL5.5

Source: Internet
Author: User
MySQL has been supporting stored procedures since MySQL 5.0 and has been using the latest version of MySQL 5.5 for several years. Although the exception handling in MYSQL is not perfect, it is sufficient to handle most applications. Exception Handling statements include the following:

MySQL has been supporting stored procedures since MySQL 5.0 and has been using the latest version of MySQL 5.5 for several years. Although the exception handling in MYSQL is not perfect, it is sufficient to handle most applications. Exception Handling statements include the following:

MySQL has been supporting stored procedures since MySQL 5.0 and has been using the latest version of MySQL 5.5 for several years. Although the exception handling in MYSQL is not perfect, it is sufficient to handle most applications.


Exception Handling statements include the following:

1. DECLARE... CONDITION.

2. DECLARE... HANDLER.

3. RESIGNAL.

4. SIGNAL.


The first type is the condition declaration.

DECLARE condition_name condition for condition_value


Here, condition_name is the standard variable name, And condition_value is the SQLSTATE value or MySQL's own error code.

Separate condition statements cannot be run directly. It can only be part of the second type.


The second type is conditional processing.

The first statement is ready, and the next step is to handle it.

DECLARE handler_action HANDLER

FOR condition_value [, condition_value]...

Statement


Handler_action:

CONTINUE

| EXIT

| UNDO


Condition_value:

Mysql_error_code

| SQLSTATE [VALUE] sqlstate_value

| Condition_name

| SQLWARNING

| NOT FOUND

| SQLEXCEPTION



Handler_action indicates the action to be processed. Currently, there are two valid actions: Hong Kong Space, continue and exit directly.

There are several condition_value types, including SQLSTATE, mysql eeror code, condition_name in the preceding condition Declaration, and other two types of range obfuscation.

SQLWARNING and SQLEXCEPTION. not found indicate any nonexistent WARNING or ERROR.


Third, it indicates the error information and code of the disguised system, and refresh the current warning buffer area.

RESIGNAL [condition_value]

[SET signal_information_item

[, Signal_information_item]...]


Condition_value:

SQLSTATE [VALUE] sqlstate_value

| Condition_name


Signal_information_item:

Condition_information_item_name = simple_value_specification


Condition_information_item_name:

CLASS_ORIGIN

| SUBCLASS_ORIGIN

| MESSAGE_TEXT

| MYSQL_ERRNO

| CONSTRAINT_CATALOG

| CONSTRAINT_SCHEMA

| CONSTRAINT_NAME

| CATALOG_NAME

| SCHEMA_NAME

| TABLE_NAME

| COLUMN_NAME

| CURSOR_NAME



Note that there are a lot of specific things that can be disguised, including the error code (MYSQL's own stuff), error content, wrong database name, table name, column name, and so on.


Fourth, there is little difference between SIGNAL and RESIGNAL. We remember that signal cannot run independently, and resignal can run independently.

SIGNAL condition_value

[SET signal_information_item

[, Signal_information_item]...]


Condition_value:

SQLSTATE [VALUE] sqlstate_value

| Condition_name


Signal_information_item:

Condition_information_item_name = simple_value_specification


Condition_information_item_name:

CLASS_ORIGIN

| SUBCLASS_ORIGIN

| MESSAGE_TEXT

| MYSQL_ERRNO

| CONSTRAINT_CATALOG

| CONSTRAINT_SCHEMA

| CONSTRAINT_NAME

| CATALOG_NAME

| SCHEMA_NAME

| TABLE_NAME

| COLUMN_NAME

| CURSOR_NAME






Here are several examples.


Do not use RESIGNAL/SIGNAL.



CALL sp_signal1 (12 );


Query result

Result

Error Code: 22

Duplicated!



Refresh the current error diagnosis area with RESIGNAL/SIGNAL.



CALL sp_signal1 (12 );

Query: call sp_signal1 (12)

Error Code: 22

Duplicated!

Execution Time: 00: 00: 00: 000

Transfer Time: 00: 00: 00: 000

Total Time: 00: 00: 00: 000


This article is from "god, let's see it !" Blog, website space, please be sure to keep this source

, Website Space

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.