从 oracle-sql 中的特定列中删除整个数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32797830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:04:05  来源:igfitidea点击:

Deleting entire data from a particular column in oracle-sql

sqloraclesql-delete

提问by RajeeV VenkaT

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

最近我开始学习了Oracle-sql。我知道在DELETE命令的帮助下我们可以删除特定的行。那么,是否可以仅使用DELETE命令从表中的特定列中删除整个数据。(我知道UPDATE通过将空值设置为整个列来使用命令,我们可以实现 的功能DELETE)。

回答by Lukasz Szozda

DELETE

删除

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

DELETE 语句从指定的表或视图中删除整行数据

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

或者如果列是 NOT NULL

UPDATE table_name
SET your_column_name = <value_indicating_removed_data>;

You can also remove entire column using DDL:

您还可以使用 DDL 删除整个列:

ALTER TABLE table_name DROP COLUMN column_name;

回答by mAEHS

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

使用来自oracle 12cR2 的Invisible Type 。

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 VISIBLEof a column name.

这比删除特定列要好。如果您需要可见,您可以通过更改VISIBLE列名来返回。

回答by Gordon Linoff

In SQL, deletedeletes rows not columns.

在 SQL 中,delete删除的是行而不是列。

You have three options in Oracle:

在 Oracle 中有三个选项:

  • Set all the values to NULLusing update.
  • Remove the column from the table.
  • Set the column to unused.
  • 将所有值设置为NULL使用更新。
  • 从表中删除该列。
  • 将列设置为未使用。

The last two use alter table:

最后两个使用alter table

alter table t drop column col;
alter table t set unused (col);

回答by malik Shaikh

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

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

this will remove all the data from the column

这将从列中删除所有数据