-4
Select m.CEAREGA, m.Crotal, rem.IdRexistro, m.IdMostraExt,
to_char(m.DataEntrega, 'DD/MM/YYYY') As Entrada, e.Descricion AS Ensaio,
to_char(rem.DataValidacion, 'DD/MM/YYYY') as DataValidacion, r.Descricion as Resultado, 
to_char(rem.Valor) as Valor, es.Descricion as Especie, tm.Descricion as Mostra,

(select LISTAGG(mo.Descricion, ':::') WITHIN GROUP (order by mo.Descricion)
from motivo_ensaio_mostra mm
join motivo_ensaio mo on mo.CodMotivo=mm.CodMotivo and mm.codLab=mo.codLab
where mm.IdRexistro=rem.IdRexistro and mm.IdMostra=rem.IdMostra and mm.CodLab=rem.CodLab
group by mm.IdRexistro, mm.IdMostra) as Motivo,

(select LISTAGG(trim(remi.NomeDesc || ' ' || remi.PrimeiroApelido || ' ' || remi.SegundoApelido), ':::') 
WITHIN GROUP (order by remi.PrimeiroApelido, remi.SegundoApelido, remi.NomeDesc)
from rexistro_remitente rm
join remitente remi on remi.NIFCIF=rm.NIFCIF and rm.codLab=remi.codLab
where rm.IdRexistro=rem.IdRexistro and rm.CodLab=rem.CodLab
group by rm.IdRexistro) as Remitente

from resultado_ensaio_mostra rem
join resultado r on r.CodResult=rem.CodResult and r.codLab = rem.codLab and r.CODTIPORESULT='P'
join mostra m on m.IdRexistro=rem.IdRexistro and m.IdMostra=rem.IdMostra and m.codLab = rem.codLab 
and m.VlxBaixa=0 and m.EstadoMostra<>10330004 and LENGTH(m.Crotal<5) and m.IdMostra > 201800000
join especie es on es.CodEspec=m.CodEspec and es.codLab = m.codLab
join tipo_mostra tm on tm.CodTipoMost=m.CodTipoMost and tm.codLab = m.codLab

它显示 Oracle 错误:ORA-00907

我找不到丢失的括号或错误在哪里。任何人都可以帮助我吗?

提前致谢。

4

2 回答 2

1

更改格式样式可能会有所帮助。

对于子查询,我尝试保持左括号和右括号明显地相互关联。我倾向于将它们放在同一列中,并将子查询的内容缩进。

同样,使每个谓词或计算彼此清楚地分开。我更喜欢将它们放在单独的行上,这样代码更长,但代码更窄;diff 这对于(等等git这样的工具更加友好。

这给了我以下内容,我可以比您的示例更快地进行可视化调试。 (事实上​​,我会说我无法直观地调试你的,每个单独的行或表达式都很难隔离和解析。)

SELECT
  m.CEAREGA,
  m.Crotal,
  rem.IdRexistro,
  m.IdMostraExt,
  to_char(m.DataEntrega, 'DD/MM/YYYY') As Entrada,
  e.Descricion AS Ensaio,
  to_char(rem.DataValidacion, 'DD/MM/YYYY') as DataValidacion,
  r.Descricion as Resultado, 
  to_char(rem.Valor) as Valor,
  es.Descricion as Especie,
  tm.Descricion as Mostra,
  (
    select
      LISTAGG(mo.Descricion, ':::')
        WITHIN GROUP (order by mo.Descricion)
    from
      motivo_ensaio_mostra mm
    join
      motivo_ensaio mo
        on  mo.CodMotivo=mm.CodMotivo
        and mm.codLab=mo.codLab
    where
          mm.IdRexistro=rem.IdRexistro
      and mm.IdMostra=rem.IdMostra
      and mm.CodLab=rem.CodLab
    group by
      mm.IdRexistro, mm.IdMostra
  ) as Motivo,
  (
    select
      LISTAGG(trim(remi.NomeDesc || ' ' || remi.PrimeiroApelido || ' ' || remi.SegundoApelido), ':::') 
        WITHIN GROUP (order by remi.PrimeiroApelido, remi.SegundoApelido, remi.NomeDesc)
    from
      rexistro_remitente rm
    join
      remitente remi
        on  remi.NIFCIF=rm.NIFCIF
        and rm.codLab=remi.codLab
    where
          rm.IdRexistro=rem.IdRexistro
      and rm.CodLab=rem.CodLab
    group by
      rm.IdRexistro
  ) as Remitente
from
  resultado_ensaio_mostra rem
join
  resultado r
    on  r.CodResult = rem.CodResult
    and r.codLab = rem.codLab
    and r.CODTIPORESULT='P'
join
  mostra m
    on  m.IdRexistro = rem.IdRexistro
    and m.IdMostra = rem.IdMostra
    and m.codLab = rem.codLab 
    and m.VlxBaixa=0
    and m.EstadoMostra<>10330004
    and LENGTH(m.Crotal<5)
    and m.IdMostra > 201800000
join
  especie es
    on  es.CodEspec=m.CodEspec
    and es.codLab = m.codLab
join
  tipo_mostra tm
    on  tm.CodTipoMost=m.CodTipoMost
    and tm.codLab = m.codLab

这使我得出结论,括号不是问题。因此,括号附近可能是其他一些语法错误。

根据我在重新格式化您的代码时出现的答案,似乎LENGTH(m.Crotal<5)应该是哪个LENGTH(m.Crotal) < 5

(本质上,在)之前有一个缺失<,在 ... 之后还有一个额外的存在5

于 2018-02-08T08:35:21.373 回答
0

多么丑陋的代码;试着习惯它的格式,这样维护起来更容易。

无论如何:错误来自AND LENGTH (m.Crotal < 5)线路。

于 2018-02-08T08:26:12.740 回答