MySQL stored procedures

Source: Internet
Author: User

DELIMITER $drop procedure if exists insert_f_arenarank$create procedure ' Insert_f_arenarank ' (in uid varchar (100)) Begindeclare _prep int;declare _id int;declare t_error INTEGER DEFAULT 0;  DECLARE EXIT HANDLER for SQLEXCEPTION SET t_error=1;start transaction; Set _prep = (select id from T_arenarank where next is null), insert into T_arenarank (USERID,PREP) values (uid,_prep); set _i D = @ @IDENTITY; Update T_arenarank Set next = _id where id=_prep;if t_error=1 then rollback;else commit;end if; End$delimiter;

1.varchar (100) brackets and their contents are not omitted;

2.# is not annotated;

3. When judging if there is an error: DECLARE EXIT HANDLER for SQLEXCEPTION SET t_error=1;

Rather than declare continue.

Attached: 3 Types of errors:   

DECLARE exit HANDLER for 1062 select ' key value repeat ';D eclare exit HANDLER for SQLEXCEPTION Select ' SQLEXCEPTION exception ';D eclare EXIT HAN Dler for SQLSTATE ' 23000 ' Select ' SQLSTATE 23000 ';

  

MySQL stored procedures

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.