Delete - (Oracle Query)
In Oracle, the DELETE
statement is used to remove one or more records from a table.
Syntax
The basic syntax for the DELETE
statement in Oracle is as follows:
DELETE FROM table_name
WHERE condition;
Here, table_name
is the name of the table from which you want to delete records, and condition
is the condition that specifies which records to delete. If you omit the WHERE
clause, all records in the table will be deleted.
Example
Let's say we have a "customers" table with the following records:
id | name | age |
---|---|---|
1 | John | 30 |
2 | Jane | 25 |
3 | Michael | 40 |
4 | Sarah | 20 |
To delete the record with the id
of 3, we can use the following Oracle DELETE
statement:
DELETE FROM customers
WHERE id = 3;
Output
1 row deleted.
After executing the DELETE
statement, the "customers" table would look like this:
id | name | age |
---|---|---|
1 | John | 30 |
2 | Jane | 25 |
4 | Sarah | 20 |
Explanation
In the above example, we used the DELETE
statement to remove the record from the "customers" table where the id
equals 3. The output shows that one row was deleted. After the DELETE
statement was executed, the "customers" table no longer contains the record with an id
of 3.
Use
The DELETE
statement is used when you want to remove one or more records from a table. It can be useful when you need to remove outdated or incorrect data from a table.
Important Points
- The
DELETE
statement is used to remove one or more records from a table. - The
WHERE
clause is used to specify which records to delete. - If the
WHERE
clause is omitted, all records in the table will be deleted.
Summary
In summary, the DELETE
statement in Oracle is used to remove one or more records from a table. The statement requires the name of the table and a condition that specifies which records to delete. If the WHERE
clause is omitted, all records in the table will be deleted. The DELETE
statement can be useful for removing outdated or incorrect data from a table.