資料庫報錯
GATHER_STATS_JOB encountered errors. Check the trace file.
Errors in file /opt/Oracle/diag/rdbms/dbserver1/dbserver1/trace/dbserver1_j003_10544.trc:
ORA-20011: Approximate NDV failed: ORA-01476: divisor is equal to zero
環境
ORACLE 11G R2
RedHat 5.3 FOR 64 BIT
解決
網上給出的結論是BUG。
Bug No: 6040840
Filed 09-MAY-2007 Updated 10-MAY-2007
Product Oracle Server - Enterprise Edition Product Version 9.2.0.8
Platform. AIX5L Based Systems (64-bit) Platform. Version No Data
Database Version 9.2.0.8 Affects Platforms Generic
Severity Severe Loss of Service Status Duplicate Bug. To Filer
Base Bug 5645718 Fixed in Product Version No Data
Problem statement:
DBMS_STATS.GATHER_TABLE_STATS FAILS WITH ORA-1476.
WORKAROUND: ----------- n/a . RELATED BUGS: ------------- Bug#5645718.
不過我的資料庫版本是11G,應該不是這個BUG。
檢查日誌發現:
*** 2012-09-29 06:00:16.870
GATHER_STATS_JOB: GATHER_TABLE_STATS('"MIS"','"T_SALES_ORDER_ITEM"','""', ...)
ORA-20011: Approximate NDV failed: ORA-01476: divisor is equal to zero
檢查T_SALES_ORDER_ITEM表發現該表select的時候也報錯:
ORA-01476: divisor is equal to zero
查看錶結構:
CREATE TABLE T_SALES_ORDER_ITEM
(
ID NUMBER(18) NOT NULL,
......
PREPAY_RATE NUMBER GENERATED ALWAYS AS (ROUND(TO_NUMBER(TO_CHAR("PREPAYMONEY"))*100/("PRICE"*"QUANTITY"),2))
......
最後 select price,quantity from T_SALES_ORDER_ITEM發現price有等於0的值!!!問題並不難解決,發現問題才是至關重要的。
修改PREPAY_RATE列,添加decode判斷函數:
PREPAY_RATE NUMBER GENERATED ALWAYS AS (DECODE("PRICE",0,0,ROUND(TO_NUMBER(TO_CHAR("PREPAYMONEY"))*100/("PRICE"*"QUANTITY"),2)))