views:

45

answers:

3

hey,

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, 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

A: 

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

UPDATE example set name=NULL, surname=NULL;
M. Jessup
+2  A: 
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".

matt b
A: 
UPDATE example
   SET name = NULL
     , surname = NULL;
DCookie