归档模式下:alter database drop datafile 'xxx/xxx.dbf';
非归档模式下 :alter database drop datafile 'xxx/xxx.dbf' offline;
以上命令只是将该数据文件OFFLINE,而不是在数据库中删除数据文件。该数据文件的信息在控制文件种仍存在。
查询v$datafile,仍显示该文件。
要彻底在数据库中删除该数据文件,只有1种方法:删除该数据文件的表空间:drop tablespace tp_xx including contents and datafiles;
--------------------------------------------------------------------
数据文件信息在两个地方保存:控制文件和数据字典,可以在NOMOUNT下重建控制文件(在创建控制文件的脚本中删除该数据文件),但这样无法删除数据字典里的信息,启动数据库后,在v$datafile里仍有这个文件,但名称变成了mising####,文件位置变成了:D:/ORACLE/ORA92/DATABASE/,文件大小变成了0.
官方文档里这样说:
DATAFILE Clauses
The DATAFILE clauses affect your database files as follows:
ONLINE
Specify ONLINE to bring the datafile online.
OFFLINE
Specify OFFLINE to take the datafile offline. If the database is open, you must perform media recovery on the datafile before bringing it back online, because a checkpoint is not performed on the datafile before it is taken offline.
DROP
If the database is in NOARCHIVELOG mode, you must specify the DROP clause to take a datafile offline. However, the DROP clause does not remove the datafile from the database. To do that, you must drop the tablespace in which the datafile resides. Until you do so, the datafile remains in the data dictionary with the status RECOVER or OFFLINE.
If the database is in ARCHIVELOG mode, Oracle ignores the DROP keyword.
DATAFILE Clauses
The DATAFILE clauses affect your database files as follows:
ONLINE
Specify ONLINE to bring the datafile online.
OFFLINE
Specify OFFLINE to take the datafile offline. If the database is open, you must perform media recovery on the datafile before bringing it back online, because a checkpoint is not performed on the datafile before it is taken offline.
DROP
If the database is in NOARCHIVELOG mode, you must specify the DROP clause to take a datafile offline. However, the DROP clause does not remove the datafile from the database. To do that, you must drop the tablespace in which the datafile resides. Until you do so, the datafile remains in the data dictionary with the status RECOVER or OFFLINE.
If the database is in ARCHIVELOG mode, Oracle ignores the DROP keyword.
--------------------------------------------------------------------
备份控制文件到trace中:alter database backup controlfile to trace [ as 'c:/ctl.bak' ];
---------------