Deletion and simple recovery of Oracle tables

                                          Deletion and simple recovery of Oracle tables

Oracle database can be regarded as an independent system, therefore, it provides a recycle bin function to prevent misuse.

Suppose I have installed an Oracle11g database, and I chose the sample emp table that comes with it during installation. The following operations are performed under OracleSQLdevelope:

1. View the table (emp table can also be manually created by yourself, see blog post for SQL statement https://blog.csdn.net/alwaysbefine/article/details/112757991 )

2, delete table data

delete from emp; In the query table, you can see that there is no content, only the table structure. Because, desc emp; can see the output is:

名称       空值 类型           
-------- -- ------------ 
EMPNO       NUMBER(4)    
ENAME       VARCHAR2(10) 
JOB         VARCHAR2(9)  
MGR         NUMBER(4)    
HIREDATE    DATE         
SAL         NUMBER(7,2)  
COMM        NUMBER(7,2)  
DEPTNO      NUMBER(2)  

 There is a second way to delete table data,

truncate table emp; At this time, if you execute rollback and roll back, you will find that the data has not come back. The truncation delete actually deletes the table data, and the delete method does not actually delete it unless it is submitted.

Simply put, truncate is the effect of delete+comit combination, and it is all table data, delete can be followed by where to select the delete column .

3. Delete the table structure. Of course, the table structure is gone, and the natural table data is gone.

drop table emp; Delete the entire table, that is, rollback rollback after drop is useless. But the Oracle system puts it in the recycle bin by default. If you query all the tables under the user at this time, you will see a recycle bin table at the beginning of bin.

Of course, if you are sure to delete this table, then the table at the beginning of the bin is garbage to you. At this time, you need to clear the garbage. After all, garbage also occupies disk space, right.

If you delete it by mistake, then the list at the beginning of this bin is your regret medicine. First, see if the recycle bin function is enabled: show parameter bin;

You can see that the recycle bin function is turned on. If you want to close the recycle bin of the entire system, you need to change the database status to mount, execute ALTER SYSTEM SET recyclebin = ON; ALTER SYSTEM SET recyclebin = OFF; to turn on or off the recycle bin function

If it is the current session-level recycle bin function switch, the command is: ALTER SESSION SET recyclebin = ON; ALTER SESSION SET recyclebin = OFF; (only valid in the current session, and invalid after changing the session). That is, if you execute off in the current session, the recycle bin function is closed, and there is no regret medicine for dropping the table.

(1) Use regret medicine

First of all, you may have a lot of regret medicines (many tables have been deleted by mistake...), but there are some medicines that you don’t regret, you just want one of them. So, here comes the question. Assuming that there are n bin tables, they are basically the same from the name alone. You don't know which bin table corresponds to which table. What should you do?

SELECT * FROM RECYCLEBIN; or SELECT * FROM USER_RECYCLEBIN; can query which table the bin table originally belongs to , for example,

Then we can specify BIN$uTo/4dQLfzXgUKjAFQAeBw==$0 This table is obtained by deleting the emps table, and is obtained by the drop operation.

Then, execute the following command to restore. If the restoration is successful, it will prompt that the flashback is successful.

flashback table "BIN$uTo/4dQNfzXgUKjAFQAeBw==$0" to before drop; --The name of the queried bin table, of course, you can add rename to at the end, and change the name when you restore directly, such as:

flashback table "BIN$uTo/4dQPfzXgUKjAFQAeBw==$0" to before drop rename to abcde; Rename this table to abcde while restoring.

(2), remove garbage

Clear all garbage: purge recyclebin; --Empty the recycle bin

Clear the specified garbage: purge table bin table name;-delete the specified garbage

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/alwaysbefine/article/details/112807638