Skip to Content
Oracle SQL*Plus Pocket Reference, 3rd Edition
book

Oracle SQL*Plus Pocket Reference, 3rd Edition

by Jonathan Gennick
November 2004
Intermediate to advanced
152 pages
2h 50m
English
O'Reilly Media, Inc.
Content preview from Oracle SQL*Plus Pocket Reference, 3rd Edition

Deleting Data

Use the DELETE statement to delete rows from a table.

Simple Deletes

A simple DELETE statement takes the following form:

DELETE FROM table_name
WHERE selection_criteria

All rows meeting the selection criteria will be deleted. For example, to delete the sixth-period Spanish I course, specify:

DELETE FROM course
WHERE course_name = 'Spanish I'
  AND period = 6;

Be careful with DELETE statements. If you omit the WHERE clause, you will delete all rows from your table.

Deleting All Rows (TRUNCATE)

You can delete all rows from a table by issuing a DELETE without a WHERE clause:

DELETE FROM course;

Deleting all rows like this exacts a price. The deletion of each row must be logged to the database redo log, and a copy of each row to be deleted must be written to a rollback segment (or to an undo tablespace) in case the transaction is rolled back. A more efficient mechanism for deleting all rows from a table is the TRUNCATE statement:

TRUNCATE TABLE course;

The TRUNCATE statement requires only one short entry in the database redo log and generates no rollback or undo data. As a result, it is faster to truncate a table than it is to delete all rows using a DELETE statement. Beware, however, that you cannot roll back a TRUNCATE statement. Once you issue it, all the data in your table is gone for good.

By default, TRUNCATE deallocates all extents assigned to the table. If you wish, you can save the extents for later use:

TRUNCATE TABLE course REUSE STORAGE;

This resets the table’s highwater mark ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Oracle SQL*Plus Pocket Reference

Oracle SQL*Plus Pocket Reference

Jonathan Gennick

Publisher Resources

ISBN: 9781491926680Errata Page