mysql handler语句之一
短信预约 -IT技能 免费直播动态提醒
handler语句概述
handler类似于select语句,但又不同于后者,它只能每次查询1次记录。handler有一些特殊的功能,适用于一些特定的场景。本文介绍handler语句相关的一些知识,以便后用。
联系方式
-
微信公众号
(微信公众号每日定期分享 欢迎大家关注)
-
微信
培训课件
(收费20元已共享到百度云盘便于同学们获取)
目录
-
handler语句官方手册
-
handler语句语法
-
handler语句示例
-
handler语句适用场景
-
handler语句注意事项
handler语句官方手册
13 SQL Statement Syntax
13.2 Data Manipulation Statements
13.2.4 HANDLER Syntax
handler语句语法
HANDLER tbl_name OPEN [ [AS] alias]
HANDLER tbl_name READ index_name { = | <= | >= | < | > } (value1,value2,...)
[ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ index_name { FIRST | NEXT | PREV | LAST }
[ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name READ { FIRST | NEXT }
[ WHERE where_condition ] [LIMIT ... ]
HANDLER tbl_name CLOSE
handler语句示例
-
为handle指定一个别名用于使用多个handle
HANDLER tbl_name OPEN [ [AS] alias]
mysql> handler t_table_lock open p1;
Query OK, 0 rows affected (0.00 sec)
-
打开表和关闭表
HANDLER tbl_name OPEN [ [AS] alias]
HANDLER tbl_name CLOSE
mysql> handler t_table_lock open;
Query OK, 0 rows affected (0.00 sec)
mysql> show open tables from zxydb like 't_table_lock';
+----------+--------------+--------+-------------+
| Database | Table | In_use | Name_locked |
+----------+--------------+--------+-------------+
| zxydb | t_table_lock | 1 | 0 |
+----------+--------------+--------+-------------+
1 row in set (0.00 sec)
mysql> handler t_table_lock close;
Query OK, 0 rows affected (0.00 sec)
##
mysql> show open tables from zxydb like 't_table_lock';
+----------+--------------+--------+-------------+
| Database | Table | In_use | Name_locked |
+----------+--------------+--------+-------------+
| zxydb | t_table_lock | 0 | 0 |
+----------+--------------+--------+-------------+
1 row in set (0.00 sec)
-
读取表的记录
HANDLER tbl_name READ { FIRST | NEXT }
[ WHERE where_condition ] [LIMIT ... ]
##获取表第1条记录
mysql> handler t_table_lock read first;
+------+------+
| a | b |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.00 sec)
##获取表的下一条记录
mysql> handler t_table_lock read next;
Empty set (0.00 sec)
-
获取指定索引值的表记录
HANDLER tbl_name READ index_name { = | <= | >= | < | > } (value1,value2,...)
[ WHERE where_condition ] [LIMIT ... ]
mysql> handler t_table_lock read idx_a=(1);
+------+------+
| a | b |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.00 sec)
##
mysql> handler t_table_lock read idx_a=(2);
Empty set (0.00 sec)
-
获取指定索引的第一,下一,前一,最后的表记录
HANDLER tbl_name READ index_name { FIRST | NEXT | PREV | LAST }
[ WHERE where_condition ] [LIMIT ... ]
##
mysql> handler t_table_lock read idx_a first;
+------+------+
| a | b |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.00 sec)
##
mysql> handler t_table_lock read idx_a next;
Empty set (0.00 sec)
##
mysql> handler t_table_lock read idx_a last;
+------+------+
| a | b |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.00 sec)
##
mysql> handler t_table_lock read idx_a prev;
Empty set (0.00 sec)
handler语句适用场景
handler语句注意事项
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341