Oracle truncate & amp; delete

Source: Internet
Author: User

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"
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.