Oracle之處理synonym同義詞無效物件
Oracle之處理synonym同義詞無效物件
ORA-00980: synonym translation is no longer valid
1. 舉例,在sys使用者下建一個t表
[oracle@testdb1 ~]:testdb1> sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on Fri Nov 14 09:33:29 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table t (x number);
Table created.
SQL> insert into t values (1);
1 row created.
SQL> commit;
Commit complete.
2. 再建立一個sec使用者
SQL> create user sec identified by sec;
User created.
3. 使用sec使用者,建立同名表syn_t
SQL> conn sec/sec
ERROR:
ORA-01045: user SEC lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.
SQL> grant dba to sec;
SP2-0640: Not connected
SQL> conn /as sysdba;
Connected.
SQL> grant dba to sec;
Grant succeeded.
SQL> conn sec/sec
Connected.
SQL> create synonym syn_t for sys.t;
Synonym created.
SQL> select * from syn_t;
X
----------
1
4. 刪除sys使用者下的t表
SQL> conn /as sysdba
Connected.
SQL> drop table t purge;
Table dropped.
SQL> conn sec/sec
SQL> conn sec/sec
Connected.
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL> select * from syn_t;
select * from syn_t
*
ERROR at line 1:
ORA-00980: synonym translation is no longer valid
SQL>
+++++++++++++++++++++++++++++++++++++++++++++++++++++
#產生了無效同名
導致“ORA-00980”錯誤的原因:
1.刪除了資料庫物件,但是忘記刪除同名;
2.刪除一個使用者,但是忘記刪除與此使用者中相關的同名;
3.建立同名時,同名對應的資料庫物件已經被刪除掉了
表t刪除,但是同名還可以建立
SQL> show user;
USER is "SEC"
SQL> create synonym syn_public_t for sys.t;
Synonym created.
SQL> create synonym syn_tt for sys.t;
Synonym created.
報錯:
SQL> desc syn_tt;
ERROR:
ORA-04043: object "SYS"."T" does not exist
查詢無效物件:
SQL> set linesize 1000
SQL> SELECT OBJECT_NAME, OBJECT_TYPE, OWNER, CREATED, LAST_DDL_TIME, TIMESTAMP FROM dba_objects WHERE status = 'INVALID';
OBJECT_NAME OBJECT_TYPE OWNER CREATED LAST_DDL_TIME
-------------------------------------------------------------- ------------------- ------------------------------ ------------------- ------------------- -------------------
/53ad31cb_TagsLocator JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
/357abd97_XPathFilter JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
SYN_T SYNONYM SYS 2014-11-14 09:40:47 2014-11-14 09:40:47 2014-11-14:09:40:47
SQL>
處理辦法:
先採用方法一,再採用方法二。
方法一:
ALTER SYNONYM SYN_T compile;
SQL> ALTER SYNONYM SYN_T compile;
Synonym altered.
SQL> SELECT OBJECT_NAME, OBJECT_TYPE, OWNER, CREATED, LAST_DDL_TIME, TIMESTAMP FROM dba_objects WHERE status = 'INVALID';
OBJECT_NAME OBJECT_TYPE OWNER CREATED LAST_DDL_TIME TIMESTAMP
----------------------------------------------- ------------------- ------------------------------ ------------------- ------------------- -------------------
/53ad31cb_TagsLocator JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
/357abd97_XPathFilter JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
SYN_T SYNONYM SYS 2014-11-14 09:40:47 2014-11-14 09:40:47 2014-11-14:09:40:47
SQL> SELECT COUNT(*) FROM dba_objects WHERE status = 'INVALID' AND object_name NOT LIKE 'BIN$%' AND object_type NOT IN ('MATERIALIZED VIEW');
COUNT(*)
----------
3
不能清理。
方法二:直接刪除
查詢指令碼:
select 'drop '
|| decode (s.owner,
'PUBLIC', 'public synonym ',
'synonym ' || s.owner || '.')
|| s.synonym_name
|| ';' as "Dropping invalid synonyms:"
from dba_synonyms s
where table_owner not in ('SYSTEM', 'SYS') and db_link is null
and not exists
(select null
from dba_objects o
where s.table_owner = o.owner
and s.table_name = o.object_name)
/
SQL> select 'drop '
2 || decode (s.owner,
3 'PUBLIC', 'public synonym ',
4 'synonym ' || s.owner || '.')
5 || s.synonym_name
6 || ';' as "Dropping invalid synonyms:"
7 from dba_synonyms s
8 where table_owner not in ('SYSTEM') and db_link is null
9 and not exists
10 (select null
11 from dba_objects o
12 where s.table_owner = o.owner
13 and s.table_name = o.object_name)
14 /
Dropping invalid synonyms:
---------------------------------------------------------------------------
drop synonym SYS.SYN_T;
drop synonym SEC.SYN_PUBLIC_T;
drop synonym SEC.SYN_TT;
SQL> drop synonym SEC.SYN_TT;
SQL> drop synonym SEC.SYN_PUBLIC_T;
SQL> drop synonym SYS.SYN_T;
ORA-00980: synonym translation is no longer valid
1. 舉例,在sys使用者下建一個t表
[oracle@testdb1 ~]:testdb1> sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on Fri Nov 14 09:33:29 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table t (x number);
Table created.
SQL> insert into t values (1);
1 row created.
SQL> commit;
Commit complete.
2. 再建立一個sec使用者
SQL> create user sec identified by sec;
User created.
3. 使用sec使用者,建立同名表syn_t
SQL> conn sec/sec
ERROR:
ORA-01045: user SEC lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.
SQL> grant dba to sec;
SP2-0640: Not connected
SQL> conn /as sysdba;
Connected.
SQL> grant dba to sec;
Grant succeeded.
SQL> conn sec/sec
Connected.
SQL> create synonym syn_t for sys.t;
Synonym created.
SQL> select * from syn_t;
X
----------
1
4. 刪除sys使用者下的t表
SQL> conn /as sysdba
Connected.
SQL> drop table t purge;
Table dropped.
SQL> conn sec/sec
SQL> conn sec/sec
Connected.
+++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL> select * from syn_t;
select * from syn_t
*
ERROR at line 1:
ORA-00980: synonym translation is no longer valid
SQL>
+++++++++++++++++++++++++++++++++++++++++++++++++++++
#產生了無效同名
導致“ORA-00980”錯誤的原因:
1.刪除了資料庫物件,但是忘記刪除同名;
2.刪除一個使用者,但是忘記刪除與此使用者中相關的同名;
3.建立同名時,同名對應的資料庫物件已經被刪除掉了
表t刪除,但是同名還可以建立
SQL> show user;
USER is "SEC"
SQL> create synonym syn_public_t for sys.t;
Synonym created.
SQL> create synonym syn_tt for sys.t;
Synonym created.
報錯:
SQL> desc syn_tt;
ERROR:
ORA-04043: object "SYS"."T" does not exist
查詢無效物件:
SQL> set linesize 1000
SQL> SELECT OBJECT_NAME, OBJECT_TYPE, OWNER, CREATED, LAST_DDL_TIME, TIMESTAMP FROM dba_objects WHERE status = 'INVALID';
OBJECT_NAME OBJECT_TYPE OWNER CREATED LAST_DDL_TIME
-------------------------------------------------------------- ------------------- ------------------------------ ------------------- ------------------- -------------------
/53ad31cb_TagsLocator JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
/357abd97_XPathFilter JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
SYN_T SYNONYM SYS 2014-11-14 09:40:47 2014-11-14 09:40:47 2014-11-14:09:40:47
SQL>
處理辦法:
先採用方法一,再採用方法二。
方法一:
ALTER SYNONYM SYN_T compile;
SQL> ALTER SYNONYM SYN_T compile;
Synonym altered.
SQL> SELECT OBJECT_NAME, OBJECT_TYPE, OWNER, CREATED, LAST_DDL_TIME, TIMESTAMP FROM dba_objects WHERE status = 'INVALID';
OBJECT_NAME OBJECT_TYPE OWNER CREATED LAST_DDL_TIME TIMESTAMP
----------------------------------------------- ------------------- ------------------------------ ------------------- ------------------- -------------------
/53ad31cb_TagsLocator JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
/357abd97_XPathFilter JAVA CLASS EXFSYS 2014-10-22 14:10:56 2014-11-12 14:40:46 2014-10-22:14:10:56
SYN_T SYNONYM SYS 2014-11-14 09:40:47 2014-11-14 09:40:47 2014-11-14:09:40:47
SQL> SELECT COUNT(*) FROM dba_objects WHERE status = 'INVALID' AND object_name NOT LIKE 'BIN$%' AND object_type NOT IN ('MATERIALIZED VIEW');
COUNT(*)
----------
3
不能清理。
方法二:直接刪除
查詢指令碼:
select 'drop '
|| decode (s.owner,
'PUBLIC', 'public synonym ',
'synonym ' || s.owner || '.')
|| s.synonym_name
|| ';' as "Dropping invalid synonyms:"
from dba_synonyms s
where table_owner not in ('SYSTEM', 'SYS') and db_link is null
and not exists
(select null
from dba_objects o
where s.table_owner = o.owner
and s.table_name = o.object_name)
/
SQL> select 'drop '
2 || decode (s.owner,
3 'PUBLIC', 'public synonym ',
4 'synonym ' || s.owner || '.')
5 || s.synonym_name
6 || ';' as "Dropping invalid synonyms:"
7 from dba_synonyms s
8 where table_owner not in ('SYSTEM') and db_link is null
9 and not exists
10 (select null
11 from dba_objects o
12 where s.table_owner = o.owner
13 and s.table_name = o.object_name)
14 /
Dropping invalid synonyms:
---------------------------------------------------------------------------
drop synonym SYS.SYN_T;
drop synonym SEC.SYN_PUBLIC_T;
drop synonym SEC.SYN_TT;
SQL> drop synonym SEC.SYN_TT;
SQL> drop synonym SEC.SYN_PUBLIC_T;
SQL> drop synonym SYS.SYN_T;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1332715/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle中的同義詞SYNONYMOracle
- 詳解同義詞(synonym)
- Oracle 處理無效物件數Oracle物件
- Oracle資料庫無效物件問題處理Oracle資料庫物件
- 物件、同義詞和公有同義詞順序選取物件
- 【Oracle】-【同義詞】-public與非public同義詞Oracle
- oracle11g同義詞synonym建立及授權且刪除相關測試Oracle
- 使用datapump 匯出匯入同義詞(export and import synonym using datapump)ExportImport
- ORACLE公有/私有同義詞Oracle
- Oracle基礎 12 物件 objects 同義詞/序列/試圖/索引Oracle物件Object索引
- 匯出oracle公有同義詞Oracle
- Oracle同義詞建立方法Oracle
- Oracle同義詞 kingsql作品OracleSQL
- 6.5. 常用物件——6.5.4. 同義詞物件
- 【SYNONYM】ORA-00980錯誤處理暨刪除無效同名的SQL生成指令碼SQL指令碼
- oracle編譯無效物件Oracle編譯物件
- 匯出Oracle中的同義詞Oracle
- Oracle同義詞建立方法(轉)Oracle
- Oracle資料庫開發——同義詞Oracle資料庫
- oracle學習筆記(十四) 資料庫物件 索引 檢視 序列 同義詞Oracle筆記資料庫物件索引
- 自定義事件相容處理物件事件物件
- ORACLE資料庫壞塊的處理 (處理無物件壞快的方法)Oracle資料庫物件
- Oracle——04同義詞與資料庫連結Oracle資料庫
- 授權與同義詞
- 編譯無效物件編譯物件
- 中考常見同義詞和同義短語總結
- 多層巢狀同義詞巢狀
- 官檔同義詞學習
- 如何處理快取導致的無效曝光快取
- SAP BW ODS無效字元自動處理程式字元
- Oracle EBS 重新編譯無效物件 invalid objectOracle編譯物件Object
- 《轉》ORACLE LOB 大物件處理Oracle物件
- 自然語言處理之jieba分詞自然語言處理Jieba分詞
- SYS查詢不到的同義詞
- 資料庫鏈與同義詞資料庫
- Oracle查詢並批量編譯無效物件指令碼Oracle編譯物件指令碼
- Oracle資料鏈+同義詞+訪問遠端資料庫Oracle資料庫
- 同花色同值牌處理