我在执行程序时遇到没有找到数据的错误。但该行实际上存在于表中。请帮助我。
**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中。我无法破解为什么会发现此异常。请帮助我。
谢谢, Poova。
答案 0 :(得分:0)
当选择程序时:
select count(*) into xx from all_tables
:xx是您可以选择的一些表格。
但是当您选择sql developer 时:
select count(*) into xx from all_tables
:xx是数据库中所有表的编号。
因此,在您的情况下,您必须grant "select any table" to scott