select unique owner
from all_tables
where sysdate-50 < (select last_analyzed from dual);
我刚才写了上面的代码,很奇怪,结果跟下面的代码不一样。Oracle中奇怪的SQL执行结果
select unique owner from all_tables;
但是,如果我单独执行(select last_analyzed from dual
),会弹出一个错误。
我很困惑如何产生结果。
select unique owner
from all_tables
where sysdate-50 < (select last_analyzed from dual);
我刚才写了上面的代码,很奇怪,结果跟下面的代码不一样。Oracle中奇怪的SQL执行结果
select unique owner from all_tables;
但是,如果我单独执行(select last_analyzed from dual
),会弹出一个错误。
我很困惑如何产生结果。
last_analyzed是具有日期值的all_tables的列之一。您无法单独运行子查询
它将该last_analysed
为一列从all_tables
,因为没有在dual
这样的列 - 它的规模效应,我想。它更清晰,如果它有一个别名写:
select unique owner
from all_tables t
where sysdate-50 < (select t.last_analyzed from dual);
你不需要的子查询的一切,你可以这样做:
select unique owner
from all_tables
where last_analyzed >= sysdate-50;
(我怀疑是南辕北辙;如果'正在寻找陈旧的统计数据,我假设你想要< sysdate-50
)。
你正在收到什么错误? – Martin 2012-07-20 08:19:29
[Understanding a basic SQL query]的可能的重复(http://stackoverflow.com/questions/11518475/understanding-a-basic-sql-query) – APC 2012-07-20 08:52:00
LAST_ANALYZED是存在于子查询上下文(ALL_TABLES系统视图)中的列而不是在DUAL系统表中。伟大的APC! +1给你 – 2012-07-20 12:31:35