What is the best way to convert an int or null to boolean value in an SQL query?

前端 未结 10 1239
情话喂你
情话喂你 2021-02-06 21:07

What is the best way to convert an int or null to boolean value in an SQL query, such that:

  • Any non-null value is TRUE in the results
  • Any
10条回答
  •  天涯浪人
    2021-02-06 22:00

    The shortest one I know for Oracle:

    SELECT NVL2(nullableColumn, 1, 0) FROM someTable
    

    NVL2(value, ifNotNull, ifNull) returns ifNotNull if the value is not null, and ifNull otherwise.

提交回复
热议问题