Condição com DECODE especial

Este forum é dedicado a códigos errados que se encontram por aí, ou seja, coisas que não se deve fazer de jeito nenhum! Não coloque neste forum dúvidas! (apenas situações bizarras do nosso dia a dia :-)
Responder
DanielNN
Moderador
Moderador
Mensagens: 641
Registrado em: Seg, 03 Set 2007 3:26 pm
Localização: Fortaleza - CE
att,

Daniel N.N.

Me deparei com essa condição e DECODE combinados, não consegui segurar o riso.

Selecionar tudo

SELECT R.SET_OF_BOOKS_ID SET_OF_BOOKS_ID,
       R.PERIOD_NAME PERIOD_NAME,
       R.TO_CURRENCY_CODE TO_CURRENCY_CODE,
       R.AVG_RATE AVG_RATE
  FROM APPS.GL_TRANSLATION_RATES R, 
APPS.GL_SETS_OF_BOOKS S, 
APPS.GL_PERIOD_STATUSES P
 WHERE R.SET_OF_BOOKS_ID = S.SET_OF_BOOKS_ID
   AND S.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
--
   AND P.APPLICATION_ID = DECODE(R.SET_OF_BOOKS_ID, 0, 101, 101)
--
   AND R.PERIOD_NAME = P.PERIOD_NAME
   AND R.TO_CURRENCY_CODE = 'IGPM'
djoq
Rank: Programador Sênior
Rank: Programador Sênior
Mensagens: 54
Registrado em: Sex, 27 Jan 2012 8:16 am
Localização: Londres UK

Já apareceu isto aqui no trabalho, chamei o analista pra mostrar. Ele me disse: Se tava aí tem alguma motivo, não muda.
:-o
Não sei o que foi pior, o código ou a opinião dele.
PS: Eu era estagiário.
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Selecionar tudo

DECODE(R.SET_OF_BOOKS_ID, 0, 101, 101)
hehehehehe Eu adoro essa sessão do forum :-D
DanielNN
Moderador
Moderador
Mensagens: 641
Registrado em: Seg, 03 Set 2007 3:26 pm
Localização: Fortaleza - CE
att,

Daniel N.N.

Sem contar que queria igualar(nem sei se posso falar isso, dado a constante disfarçada de decode) APPLICATION_ID com SET_OF_BOOKS_ID.
Avatar do usuário
gpilger
Rank: Programador Júnior
Rank: Programador Júnior
Mensagens: 29
Registrado em: Qua, 21 Abr 2010 3:34 pm
Localização: Novo Hamburgo - RS
Gilson Pilger
"Por não saber que erra impossível, ele foi lá e fez" autor desconhecido

Ele deve ter feito isso pra igualar um valor casso o retorno seja nulo. Algo do tipo nvl(null,101). Porque null não é igual a nada.
thiago rawel
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Mensagens: 3
Registrado em: Ter, 16 Jan 2018 1:40 pm

Acredito que essa seria uma opção melhor...

Selecionar tudo

SELECT R.SET_OF_BOOKS_ID SET_OF_BOOKS_ID,
       R.PERIOD_NAME PERIOD_NAME,
       R.TO_CURRENCY_CODE TO_CURRENCY_CODE,
       R.AVG_RATE AVG_RATE
  FROM APPS.GL_TRANSLATION_RATES R,
APPS.GL_SETS_OF_BOOKS S,
APPS.GL_PERIOD_STATUSES P
WHERE R.SET_OF_BOOKS_ID = S.SET_OF_BOOKS_ID
   AND S.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
--
  AND ( R.SET_OF_BOOKS_ID <> 0  AND 
            P.APPLICATION_ID = R.SET_OF_BOOKS_ID ) OR 
         (P.APPLICATION_ID = 101)
--
   AND R.PERIOD_NAME = P.PERIOD_NAME
   AND R.TO_CURRENCY_CODE = 'IGPM' 
DanielNN
Moderador
Moderador
Mensagens: 641
Registrado em: Seg, 03 Set 2007 3:26 pm
Localização: Fortaleza - CE
att,

Daniel N.N.

thiago rawel escreveu:Acredito que essa seria uma opção melhor...

Selecionar tudo

SELECT R.SET_OF_BOOKS_ID SET_OF_BOOKS_ID,
       R.PERIOD_NAME PERIOD_NAME,
       R.TO_CURRENCY_CODE TO_CURRENCY_CODE,
       R.AVG_RATE AVG_RATE
  FROM APPS.GL_TRANSLATION_RATES R,
APPS.GL_SETS_OF_BOOKS S,
APPS.GL_PERIOD_STATUSES P
WHERE R.SET_OF_BOOKS_ID = S.SET_OF_BOOKS_ID
   AND S.SET_OF_BOOKS_ID = P.SET_OF_BOOKS_ID
--
  AND ( R.SET_OF_BOOKS_ID <> 0  AND 
            P.APPLICATION_ID = R.SET_OF_BOOKS_ID ) OR 
         (P.APPLICATION_ID = 101)
--
   AND R.PERIOD_NAME = P.PERIOD_NAME
   AND R.TO_CURRENCY_CODE = 'IGPM' 
Não. Um grande problema é que:

Selecionar tudo

P.APPLICATION_ID = R.SET_OF_BOOKS_ID
são duas informações totalmente diferentes. É comparar maçã com bicicleta.
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Acho que seria perfeito assim:

Selecionar tudo

AND P.APPLICATION_ID = 101
:-D
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 12 visitantes