9

Recently I have started learning Oracle-sql. I know that with the help of DELETE command we can delete a particular row(s). So, Is it possible to delete entire data from a particular column in a table using only DELETE command. (I know that using UPDATE command by setting null values to entire column we can achieve the functionality of DELETE).

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rajeev
  • 442
  • 1
  • 5
  • 18
  • 2
    `UPDATE table SET your_column_name = NULL` DELETE removes rows, alternatively you can get rid of column using `ALTER table DROP COLUMN name` (not recommended) – Lukasz Szozda Sep 26 '15 at 13:43
  • @lad2025 Thank you. Now I clearly understood that DELETE removes only rows but not entire data from a particular column. – Rajeev Sep 26 '15 at 13:53

4 Answers4

26

DELETE

The DELETE statement removes entire rows of data from a specified table or view

If you want to "remove" data from particular column update it:

UPDATE table_name
SET your_column_name = NULL;

or if column is NOT NULL

UPDATE table_name
SET your_column_name = <value_indicating_removed_data>;

You can also remove entire column using DDL:

ALTER TABLE table_name DROP COLUMN column_name;
Yahor M
  • 617
  • 8
  • 8
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
2

In SQL, delete deletes rows not columns.

You have three options in Oracle:

  • Set all the values to NULL using update.
  • Remove the column from the table.
  • Set the column to unused.

The last two use alter table:

alter table t drop column col;
alter table t set unused (col);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
2

Use Invisible Type, which is from an oracle 12cR2.

ALTER TABLE LOG1
MODIFY operation  INVISIBLE

It is a better than drop of a particular column.If you need to visible you can get back by altering with an VISIBLE of a column name.

Shaminder Singh
  • 1,283
  • 2
  • 18
  • 31
mAEHS
  • 21
  • 1
-1

update employee set commission=nvl2(commission,'','')

this will remove all the data from the column

MarmiK
  • 5,639
  • 6
  • 40
  • 49