Select Oracle returning numerous times the same result

Asked

Viewed 476 times

0

My select works and returns the data I need, but it is returning more than 6000 times the same result.

How do I get it to return the result in just 01 line.

NOTE: There is only one result for this code sq_transação, there is no possibility of duplicity or other records with the same code, what you want to do is show the same result several times.

Select  T.Cd_Fase, F.ds_Fase, T.Nu_Msisdn, p.cd_tecnologia,T.Nu_Iccid Simcard, Sq_Transacao, To_char(Dh_Entrada, 'DD/MM/YY, HH24:MI:SS') Data, T.Cd_Erro_Api 
  from transacao t, Fase_Processamento F, plano p
  where F.Cd_Fase = T.Cd_Fase --and Nu/Msisdn In ('');
  and sq_transacao = '12590061';
  • 1

    tries to place a DISTINCT after Select to see if it resolves.

3 answers

1


As his friend Joel Rodrigues said

As you are doing select over several tables, the end result is a cross of the records. Use instead an Inner Join to relate the tables.

You do it to be legible.

SELECT DISTINCT
       SQ_TRANSACAO,
       T.CD_FASE,
       F.DS_FASE,
       T.NU_MSISDN,
       TEC.DS_TECNOLOGIA,
       C.NO_CLIENTE,
       C.NU_CPF,
       T.NU_ICCID SIMCARD,
       TO_CHAR(DH_ENTRADA, 'DD/MM/YY, HH24:MI:SS') DATA,
       T.CD_ERRO_API 
FROM TRANSACAO T,
INNER JOIN FASE_PROCESSAMENTO F ON F.CD_FASE = T.CD_FASE
INNER JOIN PLANO P ON O.SQ_PLANO = T.SQ_PLANO
INNER JOIN TECNOLOGIA TEC ON TEC.CD_TECNOLOGIA ON P.CD_TECNOLOGIA
INNER JOIN CLIENTE C ON C.SQ_CLIENTE = T.SQ_CLIENTE
WHERE SQ_TRANSACAO IN ('12590061','12590062', '12590063');

1

As you are doing select over several tables, the end result is a cross of the records. Use instead an Inner Join to relate the tables.

0

I resolved using a distinct and improving the relationship in the tables.

Select distinct  Sq_Transacao,T.Cd_Fase, F.ds_Fase, T.Nu_Msisdn, tec.ds_tecnologia, c.no_cliente, c.nu_cpf, T.Nu_Iccid Simcard, To_char(Dh_Entrada, 'DD/MM/YY, HH24:MI:SS') Data, T.Cd_Erro_Api 
  from transacao t, Fase_Processamento F, plano p, tecnologia tec, cliente c
  where F.Cd_Fase = T.Cd_Fase 
  and p.sq_plano = t.sq_plano 
  and p.cd_tecnologia = tec.cd_tecnologia
  and c.sq_cliente = t.sq_cliente
  and sq_transacao in ('12590061','12590062', '12590063');

Browser other questions tagged

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