oracle equivalent of mysql ifnull (no case, no if)

2019-09-12 18:03发布

问题:

I am looking for a quick way to do

SELECT IFNULL(columna, columnb) FROM mytable

(I have dozens of columns and don't want to write a case for each of them)

回答1:

You can also use the standard COALESCE keyword, which allows you to pass it multiple parameters:

SELECT COALESCE(columna, columnb, ..., columnz) FROM mytable

COALESCE keyword documentation



回答2:

just found out:

SELECT nvl(columna, columnb) FROM mytable

http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions105.htm