Thursday, February 12, 2009

DECODE function in SQL

In sql, we can put validation logic by using the DECODE statement

For e.g. if we have a scenario such that all First Names are to be printed out for people who are aged 60, this can be written using decode statement such as

decode(age, 60, first_name, null),


If we add an extra condition to it such that print out the First Names only if they are a Male, then we write as below

decode(age, 60, decode(gender, male, first_name, null), null)

No comments: