时间:2021-07-01 10:21:17 帮助过:30人阅读
昨天写了人生第一个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 ;
bitsCN.com