0

执行过程时,我没有遇到数据发现错误。但该行实际上存在于表中。请帮助我。

**Code**
*CREATE OR REPLACE PACKAGE BODY SCOTT."TRUNC_ANALYZE_PKG"
as
PROCEDURE TRUNC_TABLE(v_owner in varchar2, v_tab_name IN VARCHAR2) AS
    t_owner varchar2(30) ;
BEGIN
   -- Truncate only EMP tables
   SELECT     owner
     INTO     t_owner
     FROM     all_tables
    WHERE     table_name = upper(v_tab_name)
                and owner in ('EMP') ;
execute immediate ('TRUNCATE TABLE EMP.'||upper(v_tab_name)) ;
  EXCEPTION
      WHEN NO_DATA_FOUND
      THEN
              RAISE_APPLICATION_ERROR(-20023, v_tab_name||' Schema name or Table name is not valid. '||SUBSTR(SQLERRM,1,500));
      WHEN OTHERS
      THEN
              RAISE_APPLICATION_ERROR(-20023, v_tab_name||SUBSTR(SQLERRM,1,500));
END TRUNC_TABLE;
PROCEDURE ANALYZE_TABLE(v_owner in varchar2, v_tab_name IN VARCHAR2) AS
 v_tab_owner varchar2(30) := upper(v_owner) ;
 v_tab_name2 varchar2(30) := upper(v_tab_name) ;
BEGIN
dbms_ddl.analyze_object('TABLE',v_tab_owner,v_tab_name2,'ESTIMATE','',20,'');
exception
   when others then
      /* Raise the error to the calling proc id
required. */
      raise;
END ANALYZE_TABLE;
END TRUNC_ANALYZE_PKG;
/*

错误信息:

SQL> exec SCOTT.DBA_PKG.TRUNC_TABLE('EMP','EMPLOYEE');
BEGIN DBA_PKG.TRUNC_TABLE('EMP','EMPLOYEE'); END;

*
ERROR at line 1:
ORA-20023: STG_FIRMINFO Schema name or Table name is not valid. ORA-01403: no
data found
ORA-06512: at "EIB_USER.DBA_PKG", line 21
ORA-06512: at line 1

但实际上 EMPLOYEE 表存在于 all_tables 中。我无法破解为什么会捕获此异常。请帮助我。

谢谢,波瓦。

4

1 回答 1

0

当您在过程中选择时:: select count(*) into xx from all_tablesxx 是您可以选择的表数。

但是当您在 sql developer :: 中选择时, select count(*) into xx from all_tablesxx 是数据库中所有表的数量。

因此,在您的情况下,您必须grant "select any table" to scott

于 2017-10-17T08:43:46.750 回答