Analytics

Friday, March 22, 2013

Oracle DELETE Command

The SQL DELETE statement allows you to delete a single record or multiple records from a table. You can rollback deleted records before commit.

DELETE By Using Where Clause

WHERE clause is used to control which rows are affected by the DELETE statement

SQL> DELETE FROM Employee
  2     WHERE EMPID = '04';

1 rows deleted.

SQL> DELETE FROM Employee
  2     WHERE salary > 3000;

5 rows deleted.

If you don't mention the WHERE condition then all rows will be deleted.

Delete by using subquery

Suppose we want to delete all employees whose salary is greater than average salary.
Then Write a DELETE Statement Containing a Subquery.

SQL> DELETE FROM employee
  2     WHERE salary >
  3        (SELECT AVG(salary)
  4         FROM employee);

4 rows deleted.

No comments:

Post a Comment