SQLite equivalent to ISNULL(), NVL(), IFNULL() or COALESCE()

前端 未结 6 957
夕颜
夕颜 2020-11-30 00:56

I\'d like to avoid having many checks like the following in my code:

myObj.someStringField = rdr.IsDBNull(someOrdinal) 
                            ? string.         


        
6条回答
  •  萌比男神i
    2020-11-30 01:32

    Try this

    ifnull(X,Y)  
    

    e.g

    select ifnull(InfoDetail,'') InfoDetail; -- this will replace null with ''
    select ifnull(NULL,'THIS IS NULL');-- More clearly....
    

    The ifnull() function returns a copy of its first non-NULL argument, or NULL if both arguments are NULL. Ifnull() must have exactly 2 arguments. The ifnull() function is equivalent to coalesce() with two arguments.

提交回复
热议问题