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

前端 未结 10 1228
情话喂你
情话喂你 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

    In Oracle, assuming you use 0 for false and 1 for true:-

    SELECT DECODE( col, NULL, 0, 1) FROM ...
    

    You can also write this using the CASE syntax, but the above is idiomatic in Oracle. DECODE is a bit like a switch/case; if col is NULL then 0 is returned, else 1.

提交回复
热议问题