Tigran Shahnazaryan
Tigran Shahnazaryan

Reputation: 178

Update Oracle statement

I have 2 fields code and house

code                                house 

01-001-0001-0001-0001                 6
01-001-0001-0001-0002                 6 
01-001-0001-0001-0003                 6
01-001-0001-0001-0004                 6
01-001-0001-0001-****                 6

01-001-0001-0002-0001                 8
01-001-0001-0002-0002                 8
01-001-0001-0002-0003                 8
01-001-0001-0002-****                 8

How can I update house = null to obtain

code                                house 

01-001-0001-0001-0001                 6
01-001-0001-0001-0002                  
01-001-0001-0001-0003                 
01-001-0001-0001-0004                 
01-001-0001-0001-****

01-001-0001-0002-0001                 8
01-001-0001-0002-0002                 
01-001-0001-0002-0003
01-001-0001-0002-****

Upvotes: 0

Views: 80

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

How about this:

update t
    set house = NULL
    where code not like '%-0001';

If you just want this as the result of a select query:

select code,
       (case when code like '%-0001' then house end) as house
from t;

Upvotes: 4

Related Questions