8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

15.2.16 表语句15.2.16 TABLE Statement

TABLE 是一个 DML 语句,用于返回命名表的行和列。TABLE is a DML statement which returns rows and columns of the named table.

TABLE table_name 
    [ORDER BY column_name] 
    [LIMIT number [OFFSET number]]
    [INTO OUTFILE 'file_name'
        [{FIELDS | COLUMNS}
            [TERMINATED BY 'string']
            [[OPTIONALLY] ENCLOSED BY 'char']
            [ESCAPED BY 'char']
        ]
        [LINES
            [STARTING BY 'string']
            [TERMINATED BY 'string']
        ]
    | INTO DUMPFILE 'file_name'
    | INTO var_name [, var_name] ...]

TABLE 语句在某些方面类似于 SELECT。鉴于存在一个名为 t,以下两个语句输出完全相同:The TABLE statement in some ways acts like SELECT. Given the existence of a table named t, the following two statements produce identical output:

TABLE t;

SELECT * FROM t;

你可以使用 TABLEORDER BY 和 ORDER BY。当这些子句与 SELECT(包括可选的 OFFSET 子句,带 LIMIT时,功能与相同子句相同,正如你在这里看到的:You can order and limit the number of rows produced by TABLE using ORDER BY and LIMIT clauses, respectively. These function identically to the same clauses when used with SELECT (including an optional OFFSET clause with LIMIT), as you can see here:

mysql> TABLE t;
+----+----+
| a  | b  |
+----+----+
|  1 |  2 |
|  6 |  7 |
|  9 |  5 |
| 10 | -4 |
| 11 | -1 |
| 13 |  3 |
| 14 |  6 |
+----+----+
7 rows in set (0.00 sec)

mysql> TABLE t ORDER BY b;
+----+----+
| a  | b  |
+----+----+
| 10 | -4 |
| 11 | -1 |
|  1 |  2 |
| 13 |  3 |
|  9 |  5 |
| 14 |  6 |
|  6 |  7 |
+----+----+
7 rows in set (0.00 sec)

mysql> TABLE t LIMIT 3;
+---+---+
| a | b |
+---+---+
| 1 | 2 |
| 6 | 7 |
| 9 | 5 |
+---+---+
3 rows in set (0.00 sec)

mysql> TABLE t ORDER BY b LIMIT 3;
+----+----+
| a  | b  |
+----+----+
| 10 | -4 |
| 11 | -1 |
|  1 |  2 |
+----+----+
3 rows in set (0.00 sec)

mysql> TABLE t ORDER BY b LIMIT 3 OFFSET 2;
+----+----+
| a  | b  |
+----+----+
|  1 |  2 |
| 13 |  3 |
|  9 |  5 |
+----+----+
3 rows in set (0.00 sec)

TABLE 与 SELECT 在两个关键方面不同:TABLE differs from SELECT in two key respects:

  • TABLE 始终显示表的所有列。TABLE always displays all columns of the table.

    Exception:TABLE 不包含可见列。参见 第 15.1.20.10 节,“Invisible Columns”。Exception: The output of TABLE does not include invisible columns. See Section 15.1.20.10, “Invisible Columns”.

  • TABLE不允许任意过滤行;也就是说,TABLE不支持任何 WHERE子句。TABLE does not allow for any arbitrary filtering of rows; that is, TABLE does not support any WHERE clause.

For limiting which table columns are returned, filtering rows beyond what can be accomplished using ORDER BY以及LIMIT, or both, use SELECT.For limiting which table columns are returned, filtering rows beyond what can be accomplished using ORDER BY and LIMIT, or both, use SELECT.

TABLE 可以与临时表一起使用。TABLE can be used with temporary tables.

TABLE 也可以在许多其他构造中替代 SELECT,包括此处列出的构TABLE can also be used in place of SELECT in a number of other constructs, including those listed here: