mysql handler語句之一
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語句注意事項
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2666381/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql語句MySql
- MySQL系列之一條SQL查詢語句的執行過程MySql
- mySql常用語句MySql
- MySQL的語句MySql
- MySQL replace語句MySql
- 【MySQL】MySQL語句最佳化MySql
- 初識mysql語句MySql
- mysql查詢語句MySql
- Mysql日期常用語句MySql
- MySQL基礎語句MySql
- Mysql小白語句整理MySql
- 【MySQL】常用拼接語句MySql
- mysql的常用語句MySql
- MySQL迴圈語句MySql
- 翻譯:DECLARE HANDLER語句(已提交到MariaDB官方手冊)
- MySQL——優化ORDER BY語句MySql優化
- MYSQL SQL語句優化MySql優化
- Mysql之查詢語句MySql
- Mysql中的DQL語句MySql
- MySQL 三種新增語句MySql
- MySQL 四種新增語句MySql
- mysql查詢語句集MySql
- MySQL -update語句流程總結MySql
- MySQL檢視建表語句MySql
- 學習MySQL的select語句MySql
- MySQL語句執行分析(一)MySql
- MySQL語句執行分析(二)MySql
- mysql建立外來鍵語句MySql
- 入門MySQL——DML語句篇MySql
- mysql高階查詢語句MySql
- mysql 常用sql語句 簡介MySql
- 手擼Mysql原生語句--多表MySql
- MySQL中常用的SQL語句MySql
- mysql 語句如何最佳化MySql
- MySQL基礎之DML語句MySql
- MySQL的update語句避坑MySql
- MySQL 的 EXPLAIN 語句及用法MySqlAI
- MySQL基本操作語句小結MySql