Mysql database Exception Handling Code instance

Source: Internet
Author: User

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:

 
 
  1. DROP PROCEDURE IF EXISTS sp_call_jobs;  
  2.  
  3. CREATE PROCEDURE sp_call_jobs)  
  4.  
  5. NOT DETERMINISTIC  
  6.  
  7. SQL SECURITY DEFINER  
  8.  
  9. COMMENT ''  
  10.  
  11. BEGIN  
  12.  
  13. declare _row,_err,_count int default 0;  
  14.  
  15. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND set _err=1;  
  16.  
  17. while _row<3 DO  
  18.  
  19. START TRANSACTION;  
  20.  
  21. insert into t1cond_val)valuesnull);  
  22.  
  23. COMMIT;  
  24.  
  25. if _err=1 then  
  26.  
  27. set _count_count=_count+1;  
  28.  
  29. end if;  
  30.  
  31. set _row_row=_row+1;  
  32.  
  33. end while;  
  34.  
  35. select _count;  
  36.  
  37. 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!

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.