您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
handler类似于select语句,但又不同于后者,它只能每次查询1次记录。handler有一些特殊的功能,适用于一些特定的场景。本文介绍handler语句相关的一些知识,以便后用。
微信公众号
(微信公众号每日定期分享 欢迎大家关注)
微信
(收费20元已共享到百度云盘便于同学们获取)
handler语句官方手册
handler语句语法
handler语句示例
handler语句适用场景
handler语句注意事项
13 SQL Statement Syntax 13.2 Data Manipulation Statements 13.2.4 HANDLER Syntax
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
为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语句注意事项
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。