Search code examples
sqloracle11gisnullnotnull

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


Solution

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