And C #Exception HandlingMethods are very similar,MysqlIt also provides its own methods to handle exceptions. This article lists the code for mysql to process instances. Through the code, we can understand the principles and methods of mysql database exception handling.
The specific instance code is as follows:
- DROP PROCEDURE IF EXISTS sp_call_jobs;
-
- CREATE PROCEDURE sp_call_jobs)
-
- NOT DETERMINISTIC
-
- SQL SECURITY DEFINER
-
- COMMENT ''
-
- BEGIN
-
- declare _row,_err,_count int default 0;
-
- DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND set _err=1;
-
- while _row<3 DO
-
- START TRANSACTION;
-
- insert into t1cond_val)valuesnull);
-
- COMMIT;
-
- if _err=1 then
-
- set _count_count=_count+1;
-
- end if;
-
- set _row_row=_row+1;
-
- end while;
-
- select _count;
-
- END;
Statement:
Declare continue handler for sqlexception, SQLWARNING, not found set _ err = 1;
When an SQLEXCEPTION, SQLWARNING, and not found error occurs, SET _ err = 1 and execute the CONTINUE operation, that is, CONTINUE to execute the following statement.
We also use the TRANSACTION statement: start transaction ;...... COMMIT; can ensure integrity.
This article introduces these. For more information about mysql, please go to http://database.51cto.com/mysql/. thank you for your support!