SeattleGray
SeattleGray

Reputation: 95

Oracle sql - assign value to nulls or keep value if not null

I have this task where I need to assign a value if the value is null.

if its not null then I want to keep the value that is already there.. (this is what is stumping me) I know its got to be easy..

Thanks, Al

Upvotes: 1

Views: 1414

Answers (2)

Zachary Yates
Zachary Yates

Reputation: 13386

Coalesce() is what you should use, it's part of the ansi-99 standard as well.

Update [Table] Set
   Col1 = coalesce(Col1, @Col1Val)
  ,Col2 = coalesce(Col2, @Col2Val)
Where ...

Upvotes: 1

Glenn
Glenn

Reputation: 9150

UPDATE myTable
  SET myCol = myDefaultValue
  WHERE myCol IS NULL;

Upvotes: 2

Related Questions