Problema com PIVOT XML em query ORA-00904

Dúvidas, dicas e truques de SQL, Select, Update, Delete, cláusulas, operações com joins, Funções em SQLs, etc
oliveira.tadeu
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Mensagens: 5
Registrado em: Qui, 04 Jan 2018 10:18 am

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
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5023
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

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.
oliveira.tadeu
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Mensagens: 5
Registrado em: Qui, 04 Jan 2018 10:18 am

Me desculpe mas está bem longe de ser o mesmo problema, pois a query é bem diferente.
DanielNN
Moderador
Moderador
Mensagens: 641
Registrado em: Seg, 03 Set 2007 3:26 pm
Localização: Fortaleza - CE
att,

Daniel N.N.

Qual a mensagem completa do erro?
oliveira.tadeu
Rank: Estagiário Pleno
Rank: Estagiário Pleno
Mensagens: 5
Registrado em: Qui, 04 Jan 2018 10:18 am

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.
Anexos
dados.jpg
dados.jpg
Responder
  • Informação
  • Quem está online

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