更新时间:2024-04-09 GMT+08:00
分享

SHOW TABLES

语法

SHOW TABLES [ (FROM | IN) schema ] [ LIKE pattern [ESCAPE escapeChar] ]

描述

这个表达式用于列出指定schema下的所有表。如果没有指定schema,则默认使用当前所在的schema。

可选参数like被用于基于关键字来进行匹配。

示例

--创建测试表
Create table show_table1(a int);
Create table show_table2(a int);
Create table showtable5(a int);
Create table intable(a int);
Create table fromtable(a int);
 
--匹配单字符'_'
show tables in  default like 'show_table_';
  Table    
-------------
 show_table1 
 show_table2 
(2 rows)
 
--匹配多字符'*','%'
show tables in default like 'show%';
Table    
-------------
 show_table1 
 show_table2 
 showtable5  
(3 rows)
 
show tables in default like 'show*';
Table    
-------------
 show_table1 
 show_table2 
 showtable5  
(3 rows)
 
--转义字符使用,第二个示例将'_'作为过滤条件,结果集不包含showtable5  
show tables in default like 'show_%';
    Table    
-------------
 show_table1 
 show_table2 
 showtable5  
(3 rows)
 
show tables in default like 'show$_%' ESCAPE '$';
    Table    
-------------
 show_table1 
 show_table2 
(2 rows)
 
--同时满足多个条件,查询default中'show_'开头或者'in'开头的表
show tables in default like 'show$_%|in%' ESCAPE '$';
    Table    
-------------
 intable     
 show_table1 
 show_table2 
(3 rows)
分享:

    相关文档

    相关产品