查询从oracle中的dba_tables获取表名

时间:2016-11-25 08:48:54

标签: sql oracle

我想使用与dba_tab_statistics的连接从dba_tables中获取表名。

select table_name 
from dba_tables a,
     dba_tab_statistics b 
where a.owner like 'Owner' and a.table_name not like '%TMP'
  and a.LAST_ANALYZED IS NOT NULL and a.table_name = b.table_name
  and b.stattype_locked IS NULL;  

此查询不提供不同的表名。需要进行哪些更改?

2 个答案:

答案 0 :(得分:1)

使用其中任何一个:

SELECT a.table_name
  FROM dba_tables a, 
        dba_tab_statistics b
 WHERE     a.owner LIKE 'Owner'
       AND a.table_name NOT LIKE '%TMP'
       AND a.LAST_ANALYZED IS NOT NULL
       AND a.table_name = b.table_name
       AND b.stattype_locked IS NULL
 group by a.table_name ;

SELECT DISTINCT a.table_name
  FROM dba_tables a, 
        dba_tab_statistics b
 WHERE     a.owner LIKE 'Owner'
       AND a.table_name NOT LIKE '%TMP'
       AND a.LAST_ANALYZED IS NOT NULL
       AND a.table_name = b.table_name
       AND b.stattype_locked IS NULL ;

答案 1 :(得分:0)

另一种解决方案:

SELECT table_name
  FROM dba_tables a
 WHERE owner LIKE 'Owner'
   AND table_name NOT LIKE '%TMP'
   AND LAST_ANALYZED IS NOT NULL
   AND exists (SELECT 0 
              FROM dba_tab_statistics b
              WHERE a.table_name = b.table_name
              AND b.stattype_locked IS NULL);