Oracle

Oracle:我刪除了一個表,但選擇仍然顯示它

  • April 5, 2022

我今天在我的 oracle 數據庫上看到了一件奇怪的事情。

SQL> select tablespace_name, table_name from user_tables;

TABLESPACE_NAME                                       |TABLE_NAME
------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SYSTEM                                            |lavoratori2

1 riga selezionata.

Passati: 00:00:00.07
SQL> drop table lavoratori2 purge;
drop table lavoratori2 purge
          *
ERROR at line 1:
ORA-00942: table or view does not exist


Passati: 00:00:00.03

我以非 sys 使用者的身份嘗試過這個,現在我以 SYS 身份嘗試……同樣的事情。

SQL> select tablespace_name, table_name from all_tables where table_name ='lavoratori2';

TABLESPACE_NAME
------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
SYSTEM
lavoratori2


SQL> drop table lavoratori2;
drop table lavoratori2
          *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> 

怎麼解決?

我試圖清空垃圾桶,但不朽的桌子仍然存在

SQL> purge recyclebin;

Recyclebin purged.

SQL> select tablespace_name, table_name from all_tables where table_name ='lavoratori2';

TABLESPACE_NAME
------------------------------
TABLE_NAME
--------------------------------------------------------------------------------
SYSTEM
lavoratori2

另一個奇怪的事情..

SQL> select * from lavoratori2;
select * from lavoratori2
             *
ERROR at line 1:
ORA-00942: table or view does not exist

如果我這樣做了

select * from "lavoratori2";

返回

ORA-00942: table or view does not exist

如果我這樣做了

SQL> select owner from all_tables where table_name ='lavoratori2';

返回作為表所有者的非 sys 使用者的正確名稱。

首先,如果您沒有以表的所有者身份連接,則應始終在表名前加上所有者。如果您實際上以所有者的身份連接,這並沒有什麼壞處。以 THE_USER 身份連接(可以是 SYS 或任何其他使用者),

select * from lavoratori2;
--is equivalent to
select * from THE_USER.lavoratori2;

drop table lavoratori2;
--is equivalent to
drop table THE_USER.lavoratori2;

所以只有當 THE_USER 是表的所有者時它才有效。

其次,我懷疑名字的大小寫也很重要。Oracle 對對象名的預設是大寫的,所以如果你使用小寫你需要顯式地轉義它,否則它被認為是大寫的:

select * from lavoratori2;
--is equivalent to
select * from "LAVORATORI2";

drop table lavoratori2;
--is equivalent to
drop table "LAVORATORI2";

您的查詢顯示您的表名是小寫的,所以應該是"lavoratori2".

回顧一下,試試這個(用表的實際所有者替換 THE_USER):

select * from THE_USER."lavoratori2";

drop table THE_USER."lavoratori2" purge;

引用自:https://dba.stackexchange.com/questions/310542