当前位置: > 数据库 > MySQL >

MySQL 的存储过程中请求一个锁对象

时间:2016-05-26 13:52来源:linux.it.net.cn 作者:IT
mysql>
mysql> delimiter $$
mysql>
mysql> CREATE PROCEDURE myProc()
 -> BEGIN
 -> DECLARE lock_result INT;
 -> IF get_lock('sp_critical_section_lock',60) THEN
 -> 
 -> SELECT 'got lock';
 -> 
 -> SET lock_result=release_lock('sp_critical_section_lock');
 -> ELSE
 -> SELECT 'failed to acquire lock';
 -> 
 -> END IF;
 -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql> call myProc();
+----------+
| got lock |
+----------+
| got lock |
+----------+
1 row in set (0.02 sec)

Query OK, 0 rows affected (0.02 sec)

mysql>
mysql> drop procedure myProc;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
 



(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容