Home >Database >Oracle >What is the command to delete data in oracle

What is the command to delete data in oracle

WBOY
WBOYOriginal
2022-06-10 15:55:5112982browse

Oracle command to delete data: 1. delete command, which is used to delete data in the table. The syntax is "delete from table name where condition"; 2. truncate command, which can also be used to delete data. , you can directly delete the data in the table at once, the syntax is "truncate table table name".

What is the command to delete data in oracle

The operating environment of this tutorial: Windows 10 system, Oracle version 12c, Dell G3 computer.

What is the command to delete data in Oracle

Oracle delete (delete)

delete command

Table data is deleted in Oracle using the delete command.

delete command structure:

delete from 表名 where 条件

Command analysis:

1. When delete from does not add a where condition, it means that all data in the table is deleted.

Case 1. Delete the data of student "Zhang San" in the student information table (stuinfo):

delete  from stuinfo t where t.stuname='张三';

The results are as follows:

What is the command to delete data in oracle

truncate command

The truncate command is also a data deletion command. It is a command that directly deletes Oracle table data at once. The truncate command is a DDL command, unlike delete which is DML. Order.

truncate command structure:

truncate table 表名;

Case 2, delete student information backup table (stuinfo_2018):

truncate table stuinfo_2018;

The results are as follows:

What is the command to delete data in oracle

Oracle delete (delete)

Both truncate and delete can delete data in the table. Their differences:

1. TRUNCATE is a DDL command. The command Submit it after execution, and the deleted data cannot be recovered; the DELETE command is a DML command, and it must be submitted after the command is executed to take effect. The deleted data can be recovered through the log file.

2. If the amount of data in the table is large, TRUNCATE is much faster than DELETE.

3. Truncate deletion will reset the initial size of the table index, but delete cannot.

4. Delete can trigger the related delete trigger on the table, but truncate will not trigger.

5. The principle of delete is to delete data from the table one at a time, and record the deletion operation as a transaction in the database log for data rollback. Truncate deletes data pages all at once, so the execution speed is fast, but it cannot be rolled back.

Summary: The truncate command is a DDL command. It deletes all data in the table at one time, and the data cannot be restored. Use the truncate command with caution during the actual development process.

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of What is the command to delete data in oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn