Fórum tabela de referencia cruzada #482204
11/06/2014
0
Tabela1
numeros | hora | data |
5|13:00|22/01/2014|
5|13:25|22/01/2014|
5| 09:35|23/03/2014|
2|12:00|21/02/2014|
6|10:50|18/03/2014|
1|15:00|05/04/2014
preciso lista-lás da seguinte forma:
listar todos com numero 5
| 22/01/2014|23/03/2014|
| 13:00 | 09:35 |
| 13:25 |
ou listar todos com numero 1
|05/04/2014|
| 15:00 |
etc...
transformar linha em coluna.
Agradeço.
Centro Guanabara
Curtir tópico
+ 0Posts
11/06/2014
Joel Rodrigues
Gostei + 0
11/06/2014
Centro Guanabara
Gostei + 0
11/06/2014
Lourival Queiroz
begin
while true
loop
ler_registro(linha);
if (Fim_arquivo) then
goto Fim;
end if;
-- Formata a registro em n linhas
for r in (select Rownum Numero,
SUBSTR(A.Str||'|',
INSTR(A.Str||'|' , '|', 1, Rownum ) + 1,
INSTR(A.Str||'|' , '|', 1, Rownum+1) -
INSTR(A.Str||'|' , '|', 1, Rownum ) - 1) Campo
from (select '|5|13:00|22/01/2014|' Str
from dual) A,
all_objects B
where rownum < length(A.Str) - length(REPLACE(A.Str,'|')) + 1)
loop
-- Testa se Primeira Coluna está nos parametros pretendidos
if ((Numero = 1) and (Campo in ('1','5')) then
Guarda_Registro(linha); -- Guarda o registro
end if;
end loop;
<<Fim>>
fechar_arquivo;
end;
/
Gostei + 0
11/06/2014
Lourival Queiroz
(select '|5|13:00|22/01/2014|' Str
from dual) A
Vc substitui o "'|5|13:00|22/01/2014|'" por linha(registro lido)
Gostei + 0
11/06/2014
Lourival Queiroz
-- Linha = '|5|13:00|22/01/2014|'
begin
while true
loop
ler_registro(linha);
if (Fim_arquivo) then
goto Fim;
end if;
-- Formata a registro em n linhas
for r in (select Rownum Numero,
SUBSTR(A.Str||'|',
INSTR(A.Str||'|' , '|', 1, Rownum ) + 1,
INSTR(A.Str||'|' , '|', 1, Rownum+1) -
INSTR(A.Str||'|' , '|', 1, Rownum ) - 1) Campo
from (select Linha Str
from dual) A,
all_objects B
where rownum < length(A.Str) - length(REPLACE(A.Str,'|')) + 1)
loop
-- Testa se Primeira Coluna está nos parametros pretendidos
if ((Numero = 1) and (Campo in ('1','5')) then
Guarda_Registro(linha); -- Guarda o registro
end if;
-- Ler a Hora
if (Numero =2) then
pega_hora(Campo);
end if;
-- Ler a Data
if (Numero = 3) then
Pega_Data(Campo);
Finaliza(Linha) ; -- Passa para o próximo registro
end if;
end loop;
end loop;
<<Fim>>
fechar_arquivo;
end;
/
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)