Notes
1. Data can be rolled back after being deleted in oracle because it places the original data in the undo tablespace,
2. DML statements use undo tablespaces, DDL statements do not use undo, delete is a DML statement, truncate is a DDL statement, and other DDL statements are implicitly submitted. therefore, the truncate operation cannot be rolled back, while the delete operation can.
Truncate shares the same with delete:
1. The methods for deleting data in a table in oracle are delete and truncate.
2. They both Delete the data in the table, but cannot delete the table structure.
Differences between truncate and delete
1. delete: You can delete the data of the entire table or delete one or more data that meets the conditions in the table. The deleted data can be recovered. After the command is completed, you can return to the deleted data.
2 truncate: Only data in the entire table can be deleted and automatically submitted. the command cannot be returned. the truncate speed is much faster than the delete speed. After the truncate, the TABLE's HWM is returned to the positions of INITIAL and NEXT (default) delete.
4 truncate can only be set to TABLE. delete can be set to table, view, and synonym.
5. The truncate table object must be in this mode, or have the permission to drop any table, while DELETE must be in this mode, or be authorized to delete on schema. TABLE or delete any table permission.
1 truncate
Usage:
SQL code
Truncate table T;
2. delete
Usage:
SQL code
Delete T
In addition, an important difference is added.
Delete is executable in plsql, but truncate cannot be executed in plsql. It can only be executed in dynamic SQL, as shown below:
SQL code
Execute immediate 'truncate table name ';
Author: "Getting to the ground"