DROP PROCEDURE IF EXISTS pro_testincrement;
DELIMITER &&
CREATE PROCEDURE pro_testincrement(IN inr int)
BEGIN
DECLARE i INT DEFAULT 0;
select max(id) into i from testpro;
update testpro set id = id+inr where id = i;
select max(id) from testpro;
END &&
DELIMITER ;
mysql> call pro_testincrement (3);
+---------+
| max(id) |
+---------+
| 68 |
+---------+
1 row in set (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
mysql> call pro_testincrement (3);
+---------+
| max(id) |
+---------+
| 71 |
+---------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> call pro_testincrement (1);
+---------+
| max(id) |
+---------+
| 72 |
+---------+
1 row in set (0.02 sec)
Query OK, 0 rows affected (0.02 sec)
MySQL 简单存储过程实现Redis的INCR功能
标签:
本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉
本文系统来源:http://www.cnblogs.com/xiaoit/p/4576790.html