Oracle Statement重复9次!!我需要建议

时间:2014-01-15 17:18:08

标签: sql database oracle date

我有一个oracle数据库的脚本必须有错误,代码运行正常,但结果是,对于结果的每一行,是另外8行具有相同的结果。它没有显示一行,而是显示9

下面的脚本可能有什么问题?

SELECT P.IDPESSOA AS CodigoCompanhia,
       E.NOMEEMPRESA AS NomeCompanhia,
       L.LACDEBCRE AS TipoOperacao,
       L.TRGDTINCLUSAO AS DataLancamento,
       P.PLNDATDIA AS DataContabilizacao,
       L.PLACONTA AS ContaContabil,
       C.PLANOME AS DescricaoContaContabil,
       C.PLANATUREZA AS NaturezaContaContabil,
       L.LACVALOR AS ValorContabil,
       M.MOESIGLA AS Moeda,
       L.LACHIST1||' '||L.LACHIST2||' '||L.LACHIST3||' '||L.LACHIST4||' '||L.LACHIST5 AS HistoricoLancamento,
       C.PLAGRUPO AS ClasseConta,
       L.IDUSUARIOINCLUSAO AS PreparerID,
       NVL(PE.NOME, U.NOMEUSUARIO) AS NomeCompletoFuncionario,
       CG.DESCRICAO AS CargoFuncionario,
       TO_CHAR(PC.PERNOME)||'/'||TO_CHAR(P.PEREXERCICIO) AS PeriodoContabil,
       TO_CHAR(P.PLNPLANIL)||'-'||TO_CHAR(L.LACNUMLAN)||'-'||LACDEBCRE AS NumeroDocumento,
       C.PLASUBGR3 AS ContasCompensacaoTransitorias,  
       P.PLNPLANIL, L.LACNUMLAN, P.PLNCODIGO
FROM PLANILHA P, LANCAMENTO L, EMPRESAPROP E, PLANOCONTA C, PERIODO PC,
     PARAMGLOBAL PG, MOEDA M, USUARIOSISTEMA U, PESSOA PE, FUNCIONARIO F, CARGO CG
WHERE P.PLNCODIGO = L.PLNCODIGO
  AND P.PLNDATDIA >= TO_DATE('01/01/2013','DD/MM/YYYY')
  AND P.PLNDATDIA <= TO_DATE('30/04/2013','DD/MM/YYYY')
  AND P.PEREXERCICIO = PC.PEREXERCICIO
  AND P.PERNUMERO = PC.PERNUMERO
  AND P.IDPESSOA = E.IDPESSOA
  AND P.IDPESSOA = PG.IDPESSOA
  AND PG.MOEDACORRENTE = M.MOECODIGO
  AND L.PLANO = C.PLANO
  AND L.PLACONTA = C.PLACONTA
  AND L.IDUSUARIOINCLUSAO = U.IDUSUARIO
  AND U.IDUSUARIO = PE.IDPESSOA(+)
  AND PE.IDPESSOA = F.IDPESSOA(+)
  AND F.IDCARGO = CG.IDCARGO(+)
  AND P.IDPESSOA = 1
ORDER BY P.IDPESSOA, P.PLNDATDIA, P.PLNPLANIL, L.LACNUMLAN;

感谢

2 个答案:

答案 0 :(得分:1)

将select中引用的每个表的主键添加到输出列列表中。这看起来非常像其中一个表上的1:n关系;您可以通过检查每组“相等”9行中哪些PK不同来识别它是什么。

答案 1 :(得分:-1)

您也可以在'order by'子句

之前使用'group by'