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

前端 未结 6 963
夕颜
夕颜 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条回答
  •  野性不改
    2020-11-30 01:27

    For the equivalent of NVL() and ISNULL() use:

    IFNULL(column, altValue)

    column : The column you are evaluating.

    altValue : The value you want to return if 'column' is null.

    Example:

    SELECT IFNULL(middle_name, 'N/A') FROM person;

    *Note: The COALESCE() function works the same as it does for other databases.

    Sources:

    • COALESCE() Function (w3schools)
    • SQL As Understood By SQLite (SQLite website)

提交回复
热议问题