Site search

Categories

Archives

Tags

awr report delete syntax demobld demobld.sql determine oracle db size du find large file ftp script function syntax insert syntax kill oracle process linux du listener listener.log nfs mount instructions oracle constraint oracle database oracle database hosting oracle delete oracle demo build oracle demo setup oracle forein key constraint oracle ftp oracle functions oracle insert oracle process Oracle Scripts oracle select oracle subquery oracle update select syntax solaris sql background sql delete sql functions sql info sql insert sqlplus demo setup sql select sql update subquery syntax Technology Webcasts update syntax vnc tutorial vsftp
RSS
XML RSS
What is this?
AddThis Feed Button

Social
Bookmarking




-- FREE --
IT Magazine
Subscriptions

Oracle Magazine Oracle Magazine Contains technology strategy articles, sample code, tips, Oracle and partner news, how-to articles for developers and DBAs

WebSite Magazine WebSite Magazine Practical advice, helpful tools and insights for website owners

Dr Dobb's Journal Dr Dobb's Journal enables coders to write the most efficient programs and help in daily programming quandaries

DM Review DM Review is recognized as the premier business intelligence, analytics and data warehousing publication
Various other Free IT magazine subscriptions
NoAdware Free Trial

NoAdware Remove
harmful
adware,
spyware,
trojans,
dialers
and worms!
- Featured ebook -

Database Normalization
by Alf Pedersen

Database Normalization ebook Understand and master how to normalize a database using methods richly documented with graphical ERD and server diagram examples



Oracle Delete syntax

Always test these ‘oracle delete’ commands on a test server
before implementing them on a production server.

The Oracle Delete statement allows you to remove rows from a table.

The syntax is : delete from
(where );

If you specify the delete statement without the where clause, you will delete all rows from a table.

Specifying the where clause will restrict the deletion to the rows which match the restriction clause.

Here is the sample table:

SQL> select * from dept order by deptno;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 MARKETING MELBOURNE
60 IT HARTORD
70 CALLCENTRE
80 SUPPORT NONE
90 BOISE
91 SHIPPING DETROIT
92 FINANCE DETROIT

11 rows selected.

Let’s delete all rows that are located in Detroit.

SQL> delete from dept where loc = ‘DETROIT’;

2 rows deleted.

SQL> select * from dept order by deptno;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 MARKETING MELBOURNE
60 IT HARTORD
70 CALLCENTRE
80 SUPPORT NONE
90 BOISE

9 rows selected.

Now let’s select all rows that have a null value in either the dname column or the deptno column.

SQL> delete from dept where dname is null or loc is null;

2 rows deleted.

SQL> select * from dept order by deptno;

DEPTNO DNAME LOC
———- ————– ————-
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 MARKETING MELBOURNE
60 IT HARTORD
80 SUPPORT NONE

7 rows selected.

Now let’s delete all the remaining rows from this table:

SQL> delete from dept;

7 rows deleted.

SQL> select * from dept order by deptno;

no rows selected

Lastly: do not forget to commit to make your changes permanent after you use the Delete statement.

Recommended reading:

Oracle Online Documentation: SQL Reference, Delete statement