Decode vs Case Query

Asked

Viewed 278 times

3

We have two ways to work with condition within consultations in Oracle SQL, are they the Case and the Decode, the two have the same function. Allow dynamically and practice how to get a return from a column based on a condition.

What’s the difference? What’s the best? Why?

1 answer

1


The decode functions as a if of some languages condition result

EXAMPLE

SELECT DECODE(TIPO_PESSOA,'J','JURIDICA','F','FISICA','DESCONHECIDO')
FROM CLIENTES

The marry allows more complex "rules"

SELECT (CASE WHEN SALDO = 0 THEN  'BOM'
             WHEN SALDO BETWEEN 1 AND 800 THEN 'MEDIO'
             ELSE 'RUIM' END) TIPO_PAGADOR
FROM CLIENTES

see documentation for more details.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.