- 最后登录
- 2016-5-26
- 在线时间
- 35 小时
- 威望
- 8
- 金钱
- 208
- 注册时间
- 2013-1-14
- 阅读权限
- 10
- 帖子
- 60
- 精华
- 0
- 积分
- 8
- UID
- 864
|
1#
发表于 2013-2-12 14:53:59
|
查看: 5776 |
回复: 5
我希望通过如下sql查询出索引列上的选择性,可是报ORA-01476的错误
SQL> select * from
2 (
select b.table_name,a.column_name,
b.num_rows,
a.num_distinct Cardinality,
round(a.num_distinct / b.num_rows * 100, 2) selectivity
from dba_tab_col_statistics a, dba_tables b,dba_ind_columns c
where a.owner = b.owner
and b.owner = c.table_owner
and a.table_name = b.table_name
and a.column_name = c.column_name
and a.owner = 'SCOTT'
)
14 where selectivity <50;
round(a.num_distinct / b.num_rows * 100, 2) selectivity
*
ERROR at line 6:
ORA-01476: divisor is equal to zero
于是我单独运行内层的查询语句却不报任何错误
SQL> select b.table_name,a.column_name,
2 b.num_rows,
a.num_distinct Cardinality,
round(a.num_distinct / b.num_rows * 100, 2) selectivity
from dba_tab_col_statistics a, dba_tables b,dba_ind_columns c
where a.owner = b.owner
and b.owner = c.table_owner
and a.table_name = b.table_name
and a.column_name = c.column_name
10 and a.owner = 'SCOTT';
TABLE_NAME COLUMN_NAME NUM_ROWS CARDINALITY SELECTIVITY
-------------------- -------------------- ---------- ----------- -----------
DEPT DEPTNO 4 4 100
EMP DEPTNO 13 3 23.08
EMP EMPNO 13 13 100
3 rows selected.
通过ora错误可以判断当b.num_rows为0时会引发此错误,可是在内层查询中并没有这些不符的数据,为什么加了一层嵌套查询后会报ora-01476错误呢,请指教? |
|