SQL的COALESCE函示用途如下。
COALESCE函式可傳入一個以上的多個參數,返回第一個非空值參數,空值包括空字串或NULL,以Oracle SQL為例:
select coalesce(null, 'hello') val from dual; -- return 'hello'
select coalesce('', null, 'hello') val from dual; -- return 'hello'
select coalesce('', 'hi', 'hello') val from dual; -- return 'hi'
select coalesce(null, 'hi', '') val from dual; -- return 'hi'
select coalesce(null, null) val from dual; -- return null
沒有留言:
張貼留言