Thursday, August 4, 2016

Oracle decode() and sign() functions and count(*) - count(COLUMN_NAME)

decode(sign(count(*) - count(COLUMN_NAME)), 1, 'Y', 'N')

1) count(*) - count(COLUMN_NAME): returns a count of non-null records, used with group by
2) sign(NUMBER): returns sign of NUMBER
    If NUMBER < 0, then sign returns -1
    If NUMBER = 0, then sign returns 0
    If NUMBER > 0, then sign returns 1
3) decode(sign(NUMBER), 1, 'Y', 'N'): if NUMBER is greater than 0, then returns 'Y', otherwise returns 'N'

No comments: