Home > Database > Mysql Tutorial > 第一个MySQL 存储过程_MySQL

第一个MySQL 存储过程_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:30:00
Original
967 people have browsed it

bitsCN.com

昨天写了人生第一个mysql存储过程;遗憾的是,这个存储过程最后还是没用上,用php代码替代

话说mysql的存储过程真是反人类,不查reference,基本不能看懂那些语句;语言中能和它相比的,只有bash shell脚本了

好了,记录一下这个存储过程吧:

DELIMITER //CREATE PROCEDURE get_task(IN qstatus int, IN prj varchar(20))BEGIN    DECLARE task_id INT DEFAULT 0;    DECLARE done INT DEFAULT 0;    DECLARE cur CURSOR FOR        SELECT id FROM task WHERE status=qstatus and project=prj limit 1;    DECLARE EXIT HANDLER FOR SQLEXCEPTION    BEGIN                ROLLBACK;    END;    declare exit handler for not found    BEGIN                CLOSE cur;                ROLLBACK;    END;                START TRANSACTION;    OPEN cur;                FETCH cur INTO task_id;    update task set status=2 where id=task_id;    CLOSE cur;    commit;    SELECT * from task where id=task_id;ENDDELIMITER ;
Copy after login

 

bitsCN.com
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template