oracle 如何清除oracle中的单个列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2471441/
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
how to clear individual columns in oracle?
提问by user283188
i wrote a java app that communicates and stores data in oracle; my question is how do i clear entered information from individual columns in oracle? for example, say i have a following table:
我写了一个 java 应用程序,用于在 oracle 中通信和存储数据;我的问题是如何从 oracle 的各个列中清除输入的信息?例如,假设我有一个下表:
create table example (id integer, name varchar(50), surname varchar(50));
create table example (id integer, name varchar(50), surname varchar(50));
and it contains current information, how do i then clear individual columns, but keep the rest intact? For example, what if I wanted to clear name and surname columns, but leave id column intact, how would i go about doing that?
I tried by creating a new table and just copying the id column and then creating name and surname again from scratch like so:
并且它包含当前信息,然后我如何清除各个列,但保持其余部分完好无损?例如,如果我想清除 name 和 surname 列,但保留 id 列不变,我该怎么做?
我尝试通过创建一个新表并复制 id 列然后从头开始再次创建 name 和 surname ,如下所示:
create table example1 as select id from example
create table example1 as select id from example
and then issuing the alter table
command to add name and surname. Seems a bit redundant but there must be an easier way,
然后发出alter table
添加姓名和姓氏的命令。似乎有点多余,但必须有更简单的方法,
thanks
谢谢
回答by matt b
UPDATE table SET name='', surname='' WHERE ...
or
或者
UPDATE table SET name=null, surname=null WHERE ...
Of course, you'll need to make sure your table's constraints allow these values.
当然,您需要确保表的约束允许这些值。
This sounds like an odd thing to do though, rarely in an application do you need to do something like "Take ever single user/customer/account we have and erase their firstname from the datastore".
虽然这听起来很奇怪,但在应用程序中很少需要执行诸如“获取我们拥有的单个用户/客户/帐户并从数据存储中删除他们的名字”之类的操作。
回答by DCookie
UPDATE example
SET name = NULL
, surname = NULL;
回答by M. Jessup
If the columns are nullable you could just run a query to null them:
如果列可以为空,您可以运行查询将它们清空:
UPDATE example set name=NULL, surname=NULL;