Mysql stored procedures include transactions and SQL data is passed into execute _ MySQL

Source: Internet
Author: User
Mysql stored procedures include transactions and SQL data is imported for execution. it is required to use transactions in mysql stored procedures and to execute dynamic SQL statements.

The code is as follows:

BEGINDECLARE in_data TEXT;/** mark whether an error occurs */DECLARE errno int default '0';/** if an SQL exception occurs, SET t_error to 1 and then CONTINUE the subsequent operation */declare continue handler for sqlexception Rollin ROLLBACK; SET errno = 1; END; start transaction; -- PREPARE stmt FROM @ in_data; EXECUTE stmt; IF (errno = 1) then rollback; else commit; end if; SELECT errno; END
Call:
SET @ in_data = 'Insert into accounts ('userid', 'password') value (122222222,2), (22222,11) '; CALL SYN_Updata (@ in_data );
In fact, this stored procedure can be used wherever transactions are used, because the execution conditions are dynamic.

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.