Thursday, 19 March 2015

dbms_stats.gather_table_stats ORA-20000: Unable to analyze TABLE

Error:

We had issue in gather stats of a table.

 SQL> exec dbms_stats.gather_table_stats(OWNNAME=>'&Schema_name ',tabname=>'Table_name',METHOD_OPT =>'FOR ALL COLUMNS SIZE 1', CASCADE=>true, DEGREE=>4);
 BEGIN dbms_stats.gather_table_stats(OWNNAME=>'TEST ',tabname=>'TESTTable',METHOD_OPT =>'FOR ALL COLUMNS SIZE 1', CASCADE=>true, DEGREE=>4); END;

 *
 ERROR at line 1:
 ORA-20000: Unable to analyze TABLE "TEST "."TESTTable", insufficient privileges or does not exist
 ORA-06512: at "SYS.DBMS_STATS", line 23143
 ORA-06512: at "SYS.DBMS_STATS", line 23205
 ORA-06512: at line 1

Solution:

1st check the user have privilege for running gather stat,else grant the privilege

SQL> grant analyze any dictionary to <USERNAME>;

Then add ESTIMATE_PERCENT in the dbms_stats command.

SQL> exec dbms_stats.gather_table_stats(OWNNAME=>'&Schema_name ',tabname=>'Table_name',METHOD_OPT =>'FOR ALL COLUMNS SIZE 1', CASCADE=>true, DEGREE=>4);



No comments: