Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (6.1k points)
edited by
There is no equivalent to the Oracle's DECODE()'Function In Postgres`. Has anyone written the decode as a Function?

1 Answer

0 votes
by (12.7k points)

There is an equivalent. It's called a CASE statement.

There are two forms of CASE:

Simple CASE:

CASE search-expression

    WHEN expression [, expression [ ... ]] THEN

      statements

  [ WHEN expression [, expression [ ... ]] THEN

      statements

    ... ]

  [ ELSE

      statements ]

END CASE;

Searched CASE:

 CASE

    WHEN boolean-expression THEN

      statements

  [ WHEN boolean-expression THEN

      statements

    ... ]

  [ ELSE

      statements ]

END CASE;

CASE statements are easier to read; I prefer these over decode() in Oracle. 

Want to know more about SQL ? Join this SQL Certification course by Intellipaat.

Related questions

0 votes
1 answer
asked Jan 6, 2021 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 31, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...