开发者

how to clear individual columns in oracle?

开发者 https://www.devze.com 2022-12-24 11:30 出处:网络
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:

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:

create table example (id integer, 开发者_C百科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:

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,

thanks


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".


If the columns are nullable you could just run a query to null them:

UPDATE example set name=NULL, surname=NULL;


UPDATE example
   SET name = NULL
     , surname = NULL;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号