- Este tópico contém 58 respostas, 4 vozes e foi atualizado pela última vez 15 anos, 9 meses atrás por
MARCIO_LOK.
-
AutorPosts
-
16 de junho de 2010 às 4:19 pm #94595
Cassinha
Participante[u][i][b]hum, estranho, instalei essa versão e testei aqui, dá mesmo esse erro…
ORA-0006000, mesmo tirando o ALL o erro persiste.
Interessante é que na versão 9, o erro não ocorre.[/b][/i][/u]
16 de junho de 2010 às 4:23 pm #94596MARCIO_LOK
Participantevaleu, aqui o erro ocorreu tambem, mesmo tirando o ALL.
Tenho que baixar a versao toda do oracle 11 pra atualizar?
Nao consigo achar uma versao, um path mais recente do oracle 10g.Obs: As vezes demoro pra responder, porque o forum retorna pra tela principal quando clico em enviar
16 de junho de 2010 às 5:47 pm #94600Cassinha
Participante[i][u][b]Pesquisei no google e o ftjia tem razão, vai precisar atualizar mesmo
Atualiza pra ver, ate+ [/b][/u][/i] 8)16 de junho de 2010 às 8:38 pm #94611fsitja
Participante[quote=”MARCIO_LOK”:2g8yx3pa]valeu, aqui o erro ocorreu tambem, mesmo tirando o ALL.
Tenho que baixar a versao toda do oracle 11 pra atualizar?
Nao consigo achar uma versao, um path mais recente do oracle 10g.Obs: As vezes demoro pra responder, porque o forum retorna pra tela principal quando clico em enviar[/quote]
O fórum dá algum erro e volta para a página inicial quando a gente tenta enviar uma mensagem que contenham “union all”, se tirar as aspas…
16 de junho de 2010 às 9:11 pm #94614MARCIO_LOK
ParticipanteOi, entao, agora consegui processar os codigos, e os valores nao bateram, deram um numero absurdo…
infelizmente….Sem o “unio…” os valores batem, tem coerencia… coloco o “un..ion” e ele nao vem tirando o valor mes a mes…. que sera que aconteceu?
a codificacao ficou assim:
with mov_mensal as (
SELECT codconta,
nivel1,
nivel2,
nivel3,
nivel4,
nivel5,
nivel6,
nivel7,
nivel8,
nivel9,
nivel10,
nivel11,
nivel12,
nivel13,
nivel14,
nivel15,
nivel16,
nivel17,
nivel18,
nivel19,
nivel20,
ano,
sum(case when mes = '01' then mov_liq_mes end) jan,
sum(case when mes = '02' then mov_liq_mes end) fev,
sum(case when mes = '03' then mov_liq_mes end) mar,
sum(case when mes = '04' then mov_liq_mes end) abr,
sum(case when mes = '05' then mov_liq_mes end) mai,
sum(case when mes = '06' then mov_liq_mes end) jun,
sum(case when mes = '07' then mov_liq_mes end) jul,
sum(case when mes = '08' then mov_liq_mes end) ago,
sum(case when mes = '09' then mov_liq_mes end) sete,
sum(case when mes = '10' then mov_liq_mes end) out,
sum(case when mes = '11' then mov_liq_mes end) nov,
sum(case when mes = '12' then mov_liq_mes end) dez,
sum(mov_liq_mes) tot_anofrom (select c.codconta, substr(c.codconta, 1, 1) nivel1, substr(c.codconta, 1, 2) nivel2, substr(c.codconta, 1, 3) nivel3, substr(c.codconta, 1, 4) nivel4, substr(c.codconta, 1, 5) nivel5, substr(c.codconta, 1, 6) nivel6, substr(c.codconta, 1, 7) nivel7, substr(c.codconta, 1, 8) nivel8, substr(c.codconta, 1, 9) nivel9, substr(c.codconta, 1,10) nivel10, substr(c.codconta, 1,11) nivel11, substr(c.codconta, 1,12) nivel12, substr(c.codconta, 1,13) nivel13, substr(c.codconta, 1,14) nivel14, substr(c.codconta, 1,15) nivel15, substr(c.codconta, 1,16) nivel16, substr(c.codconta, 1,17) nivel17, substr(c.codconta, 1,18) nivel18, substr(c.codconta, 1,19) nivel19, substr(c.codconta, 1,20) nivel20, to_char(data, 'YYYY') ano, to_char(data, 'MM') mes, sum(case when debito is not null then -valor when credito is not null then valor end) mov_liq_mes from (select rpad(codconta, 20, '0') codconta, descricao from cconta c WHERE SubStr(codconta,1,1)='1') c left join (select rpad(c.codconta,20, '0') codconta, l.data, l.valor, l.credito, l.debito FROM cLanca L join cConta C ON L.CodColigada = C.CodColigada AND (L.Credito = C.CodConta OR L.Debito = C.CodConta) "union all" select rpad(s.codconta, 20, '0') codconta, to_date('31/12/' || (2010 - 1), 'DD/MM/YYYY') data_lanc, s.dez valor, '0' credito, null debito from saldo s) l on l.codconta = c.codconta group by c.codconta, to_char(data, 'MM'), to_char(data, 'YYYY')) group by codconta, nivel1, nivel2, nivel3, nivel4, nivel5, nivel6, nivel7, nivel8, nivel9, nivel10, nivel11, nivel12, nivel13, nivel14, nivel15, nivel16, nivel17, nivel18, nivel19, nivel20, ano) select t.codconta, c.descricao,t.jan,t.fev,t.mar,t.abr,t.mai,t.jun,t.jul,t.ago,t.sete,t.out,t.nov,t.dez,t.tot_ano,t.media from (select DISTINCT coalesce(nivel1, nivel2, nivel3, nivel4 ,nivel5, nivel6, nivel7, nivel8, nivel9, nivel10, nivel11, nivel12, nivel13, nivel14, nivel15, nivel16, nivel17, nivel18, nivel19, nivel20) codconta, Nvl(sum(jan),0) jan, Nvl(sum(fev),0) fev, Nvl(sum(mar),0) mar, Nvl(sum(abr),0) abr, Nvl(sum(mai),0) mai, Nvl(sum(jun),0) jun, Nvl(sum(jul),0) jul, Nvl(sum(ago),0) ago, Nvl(sum(sete),0) sete, Nvl(sum(out),0) out, Nvl(sum(nov),0) nov, Nvl(sum(dez),0) dez, nvl(sum(tot_ano),0) tot_ano, Nvl(Round(sum(tot_ano),2),0)/12 media from mov_mensal WHERE ( jan !=0 OR fev !=0 OR mar !=0 OR abr !=0 OR mai !=0 OR jun !=0 OR jul !=0 OR ago !=0 OR sete !=0 OR out !=0 OR nov !=0 OR dez !=0) group by grouping sets ((nivel1), (nivel2), (nivel3), (nivel4), (nivel5), (nivel6), (nivel7), (nivel8), (nivel9), (nivel10), (nivel11), (nivel12), (nivel13), (nivel14), (nivel15), (nivel16), (nivel17), (nivel18), (nivel19), (nivel20)) having (substr(nivel1, length(nivel1), 1) != '0') or (substr(nivel2, length(nivel2), 1) != '0') or (substr(nivel3, length(nivel3), 1) != '0') or (substr(nivel4, length(nivel4), 1) != '0') or (substr(nivel5, length(nivel5), 1) != '0') or (substr(nivel6, length(nivel6), 1) != '0') or (substr(nivel7, length(nivel7), 1) != '0') or (substr(nivel8, length(nivel8), 1) != '0') or (substr(nivel9, length(nivel9), 1) != '0') or (substr(nivel10, length(nivel10), 1) != '0') or (substr(nivel11, length(nivel11), 1) != '0') or (substr(nivel12, length(nivel12), 1) != '0') or (substr(nivel13, length(nivel13), 1) != '0') or (substr(nivel14, length(nivel14), 1) != '0') or (substr(nivel15, length(nivel15), 1) != '0') or (substr(nivel16, length(nivel16), 1) != '0') or (substr(nivel17, length(nivel17), 1) != '0') or (substr(nivel18, length(nivel18), 1) != '0') or (substr(nivel19, length(nivel19), 1) != '0') or (substr(nivel20, length(nivel20), 1) != '0')) t join cconta c on c.codconta = t.codcontaorder by t.codconta
16 de junho de 2010 às 9:40 pm #94617fsitja
ParticipanteMarcio, está dando errado porque você não está usando o último SQL que postei, está fazendo com um dos primeiros SQLs que postei há um tempão atrás.
Tem um punhado de coisas que foram alteradas que você não mudou ainda lá. 😉
16 de junho de 2010 às 10:12 pm #94621MARCIO_LOK
ParticipanteOhhh desculpa, postei o codigo antigo mesmo…
segue minhas alteracoes..
with mov_mensal as (
select codconta,
nivel1,
nivel2,
nivel3,
nivel4,
nivel5,
nivel6,
nivel7,
nivel8,
nivel9,
nivel10,
nivel11,
nivel12,
nivel13,
nivel14,
nivel15,
nivel16,
nivel17,
nivel18,
nivel19,
nivel20,
ano,
nvl(sum(case when mes = '12' and ano = (2010 - 1) then mov_liq_mes end), 0) saldo_ant,
nvl(sum(case when mes <= '01' then mov_liq_mes end), 0) jan,
nvl(sum(case when mes <= '02' then mov_liq_mes end), 0) fev,
nvl(sum(case when mes <= '03' then mov_liq_mes end), 0) mar,
nvl(sum(case when mes <= '04' then mov_liq_mes end), 0) abr,
nvl(sum(case when mes <= '05' then mov_liq_mes end), 0) mai,
nvl(sum(case when mes <= '06' then mov_liq_mes end), 0) jun,
nvl(sum(case when mes <= '07' then mov_liq_mes end), 0) jul,
nvl(sum(case when mes <= '08' then mov_liq_mes end), 0) ago,
nvl(sum(case when mes <= '09' then mov_liq_mes end), 0) sete,
nvl(sum(case when mes <= '10' then mov_liq_mes end), 0) out,
nvl(sum(case when mes <= '11' then mov_liq_mes end), 0) nov,
nvl(sum(case when mes <= '12' and ano = 2010 then mov_liq_mes end), 0) dez,
nvl(sum(case when ano = 2010 then mov_liq_mes end), 0) tot_ano,
nvl(sum(case when ano = 2010 then mov_liq_mes end)/12, 0) Tot_Mediafrom (select c.codconta,
substr(c.codconta, 1, 1) nivel1,
substr(c.codconta, 1, 2) nivel2,
substr(c.codconta, 1, 3) nivel3,
substr(c.codconta, 1, 4) nivel4,
substr(c.codconta, 1, 5) nivel5,
substr(c.codconta, 1, 6) nivel6,
substr(c.codconta, 1, 7) nivel7,
substr(c.codconta, 1, 8) nivel8,
substr(c.codconta, 1, 9) nivel9,
substr(c.codconta, 1,10) nivel10,
substr(c.codconta, 1,11) nivel11,
substr(c.codconta, 1,12) nivel12,
substr(c.codconta, 1,13) nivel13,
substr(c.codconta, 1,14) nivel14,
substr(c.codconta, 1,15) nivel15,
substr(c.codconta, 1,16) nivel16,
substr(c.codconta, 1,17) nivel17,
substr(c.codconta, 1,18) nivel18,
substr(c.codconta, 1,19) nivel19,
substr(c.codconta, 1,20) nivel20,
to_char(data, 'YYYY') ano,
to_char(data, 'MM') mes,
sum(case when debito is not null then valor * -1
when credito is not null then valor end) mov_liq_mes
from (select rpad(codconta, 20, '0') codconta, descricao from cconta) c
left join (select rpad(c.codconta, 20, '0') codconta,
l.data,
l.valor,
l.credito,
l.debito
from clanca l
join cConta C
ON L.CodColigada = C.CodColigada
AND (L.Credito = C.CodConta
OR L.Debito = C.CodConta)
where to_char(l.data, 'YYYY') = 2010
union
all
select rpad(s.codconta, 20, '0') codconta,
to_date('31/12/' || (2010 - 1), 'DD/MM/YYYY') data_lanc,
s.dez valor,
'0' credito,
null debito
from saldo s) l on l.codconta = c.codconta
group by c.codconta, to_char(data, 'MM'), to_char(data, 'YYYY'))
group by codconta, nivel1, nivel2, nivel3,nivel4 ,nivel5, nivel6, nivel7, nivel8, nivel9, nivel10, nivel11, nivel12, nivel13, nivel14, nivel15, nivel16, nivel17, nivel18, nivel19, nivel20, ano)
select t.codconta, c.descricao,t.jan,t.fev,t.mar,t.abr,t.mai,t.jun,t.jul,t.ago,t.sete,t.out,t.nov,t.dez,t.tot_ano, Tot_Media
from (select coalesce(nivel1, nivel2, nivel3, nivel4 ,nivel5, nivel6, nivel7, nivel8, nivel9, nivel10, nivel11, nivel12, nivel13, nivel14, nivel15, nivel16, nivel17, nivel18, nivel19, nivel20) codconta,
sum(saldo_ant) saldo_ant,
sum(saldo_ant + jan) jan,
sum(saldo_ant + fev) fev,
sum(saldo_ant + mar) mar,
sum(saldo_ant + abr) abr,
sum(saldo_ant + mai) mai,
sum(saldo_ant + jun) jun,
sum(saldo_ant + jul) jul,
sum(saldo_ant + ago) ago,
sum(saldo_ant + sete) sete,
sum(saldo_ant + out) out,
sum(saldo_ant + nov) nov,
sum(saldo_ant + dez) dez,
sum(saldo_ant + tot_ano) saldo_final,
sum(tot_ano) tot_ano,
sum(tot_ano)/12 tot_mediafrom mov_mensal group by grouping sets ((nivel1), (nivel2), (nivel3), (nivel4), (nivel5), (nivel6), (nivel7), (nivel8), (nivel9), (nivel10), (nivel11), (nivel12), (nivel13), (nivel14), (nivel15), (nivel16), (nivel17), (nivel18), (nivel19), (nivel20)) having (substr(nivel1, length(nivel1), 1) != '0') or (substr(nivel2, length(nivel2), 1) != '0') or (substr(nivel3, length(nivel3), 1) != '0') or (substr(nivel3, length(nivel4), 1) != '0') or (substr(nivel3, length(nivel5), 1) != '0') or (substr(nivel3, length(nivel6), 1) != '0') or (substr(nivel3, length(nivel7), 1) != '0') or (substr(nivel3, length(nivel8), 1) != '0') or (substr(nivel3, length(nivel9), 1) != '0') or (substr(nivel3, length(nivel10), 1) != '0') or (substr(nivel3, length(nivel11), 1) != '0') or (substr(nivel3, length(nivel12), 1) != '0') or (substr(nivel3, length(nivel13), 1) != '0') or (substr(nivel3, length(nivel14), 1) != '0') or (substr(nivel3, length(nivel15), 1) != '0') or (substr(nivel3, length(nivel16), 1) != '0') or (substr(nivel3, length(nivel17), 1) != '0') or (substr(nivel3, length(nivel18), 1) != '0') or (substr(nivel3, length(nivel19), 1) != '0') or (substr(nivel3, length(nivel20), 1) != '0') ) tjoin cconta c on c.codconta = t.codconta
where tot_ano != 0
or saldo_ant != 0
or jan != 0
or fev != 0
or mar != 0
or dez != 0
order by t.codconta;
Brigadao
16 de junho de 2010 às 10:18 pm #94622MARCIO_LOK
Participanteopa, é tanto codigo que to ficando louco, rs
considere esse como o correto e ultimo, obrigado
with mov_mensal as (
select codconta,
nivel1,
nivel2,
nivel3,
nivel4,
nivel5,
nivel6,
nivel7,
nivel8,
nivel9,
nivel10,
nivel11,
nivel12,
nivel13,
nivel14,
nivel15,
nivel16,
nivel17,
nivel18,
nivel19,
nivel20,
ano,
nvl(sum(case when mes = '12' and ano = (2010 - 1) then mov_liq_mes end), 0) saldo_ant,
nvl(sum(case when mes <= '01' then mov_liq_mes end), 0) jan,
nvl(sum(case when mes <= '02' then mov_liq_mes end), 0) fev,
nvl(sum(case when mes <= '03' then mov_liq_mes end), 0) mar,
nvl(sum(case when mes <= '04' then mov_liq_mes end), 0) abr,
nvl(sum(case when mes <= '05' then mov_liq_mes end), 0) mai,
nvl(sum(case when mes <= '06' then mov_liq_mes end), 0) jun,
nvl(sum(case when mes <= '07' then mov_liq_mes end), 0) jul,
nvl(sum(case when mes <= '08' then mov_liq_mes end), 0) ago,
nvl(sum(case when mes <= '09' then mov_liq_mes end), 0) sete,
nvl(sum(case when mes <= '10' then mov_liq_mes end), 0) out,
nvl(sum(case when mes <= '11' then mov_liq_mes end), 0) nov,
nvl(sum(case when mes <= '12' and ano = 2010 then mov_liq_mes end), 0) dez,
nvl(sum(case when ano = 2010 then mov_liq_mes end), 0) tot_ano,
nvl(sum(case when ano = 2010 then mov_liq_mes end)/12, 0) Tot_Mediafrom (select c.codconta,
substr(c.codconta, 1, 1) nivel1,
substr(c.codconta, 1, 2) nivel2,
substr(c.codconta, 1, 3) nivel3,
substr(c.codconta, 1, 4) nivel4,
substr(c.codconta, 1, 5) nivel5,
substr(c.codconta, 1, 6) nivel6,
substr(c.codconta, 1, 7) nivel7,
substr(c.codconta, 1, 8) nivel8,
substr(c.codconta, 1, 9) nivel9,
substr(c.codconta, 1,10) nivel10,
substr(c.codconta, 1,11) nivel11,
substr(c.codconta, 1,12) nivel12,
substr(c.codconta, 1,13) nivel13,
substr(c.codconta, 1,14) nivel14,
substr(c.codconta, 1,15) nivel15,
substr(c.codconta, 1,16) nivel16,
substr(c.codconta, 1,17) nivel17,
substr(c.codconta, 1,18) nivel18,
substr(c.codconta, 1,19) nivel19,
substr(c.codconta, 1,20) nivel20,
to_char(data, 'YYYY') ano,
to_char(data, 'MM') mes,
sum(case when debito is not null then valor * -1
when credito is not null then valor end) mov_liq_mes
from (select rpad(codconta, 20, '0') codconta, descricao from cconta) c
left join (select rpad(c.codconta, 20, '0') codconta,
l.data,
l.valor,
l.credito,
l.debito
from clanca l
join cConta C
ON L.CodColigada = C.CodColigada
AND (L.Credito = C.CodConta
OR L.Debito = C.CodConta)
where to_char(l.data, 'YYYY') = 2010
union
all
select rpad(s.codconta, 20, '0') codconta,
to_date('31/12/' || (2010 - 1), 'DD/MM/YYYY') data_lanc,
s.dez valor,
'0' credito,
null debito
from saldo s) l on l.codconta = c.codconta
group by c.codconta, to_char(data, 'MM'), to_char(data, 'YYYY'))
group by codconta, nivel1, nivel2, nivel3,nivel4 ,nivel5, nivel6, nivel7, nivel8, nivel9, nivel10, nivel11, nivel12, nivel13, nivel14, nivel15, nivel16, nivel17, nivel18, nivel19, nivel20, ano)
select t.codconta, c.descricao,t.jan,t.fev,t.mar,t.abr,t.mai,t.jun,t.jul,t.ago,t.sete,t.out,t.nov,t.dez,t.tot_ano, Tot_Media
from (select coalesce(nivel1, nivel2, nivel3, nivel4 ,nivel5, nivel6, nivel7, nivel8, nivel9, nivel10, nivel11, nivel12, nivel13, nivel14, nivel15, nivel16, nivel17, nivel18, nivel19, nivel20) codconta,
sum(saldo_ant) saldo_ant,
sum(saldo_ant + jan) jan,
sum(saldo_ant + fev) fev,
sum(saldo_ant + mar) mar,
sum(saldo_ant + abr) abr,
sum(saldo_ant + mai) mai,
sum(saldo_ant + jun) jun,
sum(saldo_ant + jul) jul,
sum(saldo_ant + ago) ago,
sum(saldo_ant + sete) sete,
sum(saldo_ant + out) out,
sum(saldo_ant + nov) nov,
sum(saldo_ant + dez) dez,
sum(saldo_ant + tot_ano) saldo_final,
sum(tot_ano) tot_ano,
sum(tot_ano)/12 tot_mediafrom mov_mensal group by grouping sets ((nivel1), (nivel2), (nivel3), (nivel4), (nivel5), (nivel6), (nivel7), (nivel8), (nivel9), (nivel10), (nivel11), (nivel12), (nivel13), (nivel14), (nivel15), (nivel16), (nivel17), (nivel18), (nivel19), (nivel20)) having (substr(nivel1, length(nivel1), 1) != '0') or (substr(nivel2, length(nivel2), 1) != '0') or (substr(nivel3, length(nivel3), 1) != '0') or (substr(nivel4, length(nivel4), 1) != '0') or (substr(nivel5, length(nivel5), 1) != '0') or (substr(nivel6, length(nivel6), 1) != '0') or (substr(nivel7, length(nivel7), 1) != '0') or (substr(nivel8, length(nivel8), 1) != '0') or (substr(nivel9, length(nivel9), 1) != '0') or (substr(nivel10, length(nivel10), 1) != '0') or (substr(nivel11, length(nivel11), 1) != '0') or (substr(nivel12, length(nivel12), 1) != '0') or (substr(nivel13, length(nivel13), 1) != '0') or (substr(nivel14, length(nivel14), 1) != '0') or (substr(nivel15, length(nivel15), 1) != '0') or (substr(nivel16, length(nivel16), 1) != '0') or (substr(nivel17, length(nivel17), 1) != '0') or (substr(nivel18, length(nivel18), 1) != '0') or (substr(nivel19, length(nivel19), 1) != '0') or (substr(nivel20, length(nivel20), 1) != '0') ) tjoin cconta c on c.codconta = t.codconta
where tot_ano != 0
or saldo_ant != 0
or jan != 0
or fev != 0
or mar != 0
or abr != 0
or mai != 0
or jun != 0
or jul != 0
or ago != 0
or sete != 0
or out != 0
or nov != 0
or dez != 0or dez != 0order by t.codconta;
17 de junho de 2010 às 6:12 am #94640fsitja
ParticipanteCorreto significa que funcionou ou não?
Dei uma olhada e parece estar ok… se deu algum problema, acho que o ideal seria ir testando por partes e numa versão simplificada, tipo a que eu fiz, com menos meses e tal.
Testa primeiro o select dentro do WITH, vê se vêm os valores corretos, depois vai incrementando e olhando a parte de baixo, para achar até qual ponto está vindo certo e qual não.
Se está muito doido, e como você mencionou que teria ficado estranho depois de adicionar o “union” do saldo, então essa tabela de saldo tem dados de outros anos? 2008, 2007 e por aí vai? Seria um bom motivo…
17 de junho de 2010 às 7:35 am #94641MARCIO_LOK
ParticipanteEntao… se eu tirar o “all union” ele funciona, tras o valor corretamente…
Só quando coloco o “union” que ele da uma baita diferenca….
Todos os outros selects funcionam e tras o codigo perfeitamente…Obrigado
17 de junho de 2010 às 8:42 am #94645fsitja
Participante[quote=”MARCIO_LOK”:eg6rx29o]Entao… se eu tirar o “all union” ele funciona, tras o valor corretamente…
Só quando coloco o “union” que ele da uma baita diferenca….
Todos os outros selects funcionam e tras o codigo perfeitamente…Obrigado[/quote]
Tem saldo de anos anteriores a 2009 nessa tabela também?
17 de junho de 2010 às 3:30 pm #94646MARCIO_LOK
ParticipanteBom dia..
Não tem nao, essa tabela …o saldo das contas é referente a dezembro de 2009.
17 de junho de 2010 às 8:17 pm #94651fsitja
ParticipanteDá uma olhada no retorno desse SQL:
select rpad(s.codconta, 20, '0') codconta,
sum(s.dez valor) soma,
count() cnt
from saldo s
group by rpad(s.codconta, 20, '0')
having count() > 1;
Vem alguma coisa?
17 de junho de 2010 às 8:33 pm #94652MARCIO_LOK
ParticipanteOi, entao na parte…
sum(s.dez valor) soma,
ele dá um erro….
quando eu coloquei assim
sum(s.dez) soma,
nao retornou valor nenhum, seria isso?
A tabela saldo, o nome do campo valor, é “dez”. -
AutorPosts
- Você deve fazer login para responder a este tópico.