Página 1 de 1

Problema com PIVOT XML em query ORA-00904

Enviado: Qui, 04 Jan 2018 10:33 am
por oliveira.tadeu

Selecionar tudo

select tcibem.codbem,
       tcibem.descrabrev,
       tcibem.numnota,
       nvl(ad_depacel.saldo, 0) as saldo,
       tcibem.dtfimdep,
       tcitax.taxa,
       tcibem.vlrsaldo,
       saldos.referencia,
       nvl(saldos.vlr_depreciado, 0) as vlr_depreciado
  from tcibem,
       ad_depacel,
       tgfpro,
       tcitax,
       (
       select  tcisal.codprod as codprod
       ,       tcisal.codbem  as codbem
       ,       to_char(tcisal.referencia, 'mm/yyyy') as referencia
       ,       tcisal.saldo as vlr_depreciado
       from    tcisal
       ) saldos
       pivot xml 
       (sum(nvl(vlr_depreciado, 0)) as vlr_depreciado for (referencia) in 
       (
       select to_char(referencia, 'mm/yyyy') as referencia from tcisal
       )
       )  
 where ad_depacel.codbem (+) = tcibem.codbem 
   and tgfpro.codprod = tcibem.codprod 
   and tcitax.codprod = tcibem.codprod 
   and tcibem.codbem  <> '<TODOS>'
   and tcibem.numnota is not null
   and saldos.referencia is not null
   and saldos.codprod (+) = tcibem.codprod 
   and saldos.codbem (+) = tcibem.codbem

Re: Problema com PIVOT XML em query ORA-00904

Enviado: Qui, 04 Jan 2018 10:59 am
por dr_gori
Hmm...

http://www.dba-oracle.com/t_ora_00904_s ... tifier.htm
ORA-00904 string: invalid identifier

Cause: The column name entered is either missing or invalid.

Action: Enter a valid column name. A valid column name must begin with a letter, be less than or equal to 30 characters, and consist of only alphanumeric characters and the special characters $, _, and #.

If it contains other characters, then it must be enclosed in double quotation marks. It may not be a reserved word.
Parece que o Tom Kyte tem um problema semalhante ao seu:
https://asktom.oracle.com/pls/apex/f?p= ... 0346783166
No caso dele, a solução foi colocar entre aspas duplas o nome do campo.
Veja as respostas no link acima.

Re: Problema com PIVOT XML em query ORA-00904

Enviado: Qui, 04 Jan 2018 12:56 pm
por oliveira.tadeu
Me desculpe mas está bem longe de ser o mesmo problema, pois a query é bem diferente.

Re: Problema com PIVOT XML em query ORA-00904

Enviado: Qui, 04 Jan 2018 1:42 pm
por DanielNN
Qual a mensagem completa do erro?

Re: Problema com PIVOT XML em query ORA-00904

Enviado: Qui, 04 Jan 2018 3:09 pm
por oliveira.tadeu

Selecionar tudo

select distinct * from
(
select tcibem.codbem,
       tcibem.descrabrev,
       tcibem.numnota,
       nvl(ad_depacel.saldo, 0) as saldo,
       tcibem.dtfimdep,
       tcitax.taxa,
       tcibem.vlrsaldo,
       saldos.referencia,
       nvl(saldos.vlr_depreciado, 0) as vlr_depreciado
  from tcibem,
       ad_depacel,
       tgfpro,
       tcitax,
       (
       select  tcisal.codprod as codprod
       ,       tcisal.codbem  as codbem
       ,       to_char(tcisal.referencia, 'mm/yyyy') as referencia
       ,       tcisal.saldo as vlr_depreciado
       from    tcisal
       ) saldos 
 where ad_depacel.codbem (+) = tcibem.codbem 
   and tgfpro.codprod        = tcibem.codprod 
   and tcitax.codprod        = tcibem.codprod 
   and tcibem.codbem         <> '<TODOS>'
   and tcibem.numnota        is not null
   and saldos.referencia     is not null
   and saldos.codprod    (+) = tcibem.codprod 
   and saldos.codbem     (+) = tcibem.codbem
)
pivot xml (sum(nvl(vlr_depreciado, 0)) as vlr_depreciado for (referencia) in (select to_char(referencia, 'mm/yyyy') as referencia from tcisal))  
Agora já está retornando dados conforme imagem abaixo, somente a coluna referencia_xml teria que ser o mês e ano de referência ex: 11/2017 e o conteúdo da mesma nas linhas o valor depreciado do bem ex: 58460,72.
Se alguém puder ajudar agradeço.