Oracle DELETE statement is used to delete records from the table. The syntax is: DELETE FROM table_name WHERE condition. Conditions are optional to restrict deletion of records. Supports cascade deletion, that is, when deleting parent table records, child table records can also be deleted. Use caution as deletion is irreversible.
Oracle DELETE Statement
The DELETE statement is used to delete records from an Oracle database table. The basic syntax is as follows:
DELETE FROM table_name WHERE condition;
Where:
Example:
Delete all records in the table named "customers":
DELETE FROM customers;
Delete the customer_id 10 in the "customers" table Records:
DELETE FROM customers WHERE customer_id = 10;
Delete records with multiple conditions:
You can use logical operators (AND, OR) to delete records that meet multiple conditions.
Example:
Delete records in the "customers" table whose city is "New York" and whose age is greater than 30:
DELETE FROM customers WHERE city = 'New York' AND age > 30;
level Joint deletion:
When there are foreign key constraints between tables, deleting records in the parent table may cause records in the child table to also be deleted. This is called a cascade delete.
To enable cascading deletes, the ON DELETE CASCADE option must be specified when creating the foreign key constraint.
Example:
Consider the following table structure:
CREATE TABLE orders ( order_id NUMBER PRIMARY KEY, product_id NUMBER, CONSTRAINT FK_order_product FOREIGN KEY (product_id) REFERENCES products (product_id) ON DELETE CASCADE );
If you delete a product from the "products" table, the "orders" table will also be deleted All orders that reference this product.
Note:
The above is the detailed content of How to write oracle delete statement. For more information, please follow other related articles on the PHP Chinese website!