0
CREATE TABLE TABELA_PRAZO
(
CEP_INICIO NUMBER(8) NOT NULL,
CEP_FIM NUMBER(8) NOT NULL,
PRAZO NUMBER(3) NOT NULL
);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (1000000, 1000005, 5);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (510101, 510104, 4);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (510000, 510067, 4);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (510068, 510100, 3);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (1000006, 10000010, 5);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (810000, 810001, 5);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (810002, 810003, 5);
insert into tron2000.TABELA_PRAZO(CEP_INICIO, CEP_FIM, PRAZO) values (810004, 810005, 5);
The table describes the deadlines that should be used by a freight calculation system, given a range of ZIP CODE (zip code range is an interval between CEP_INICIO
and CEP_FIM
, both included in the range). Here is a small example of the populated table:
CEP_INICIO CEP_FIM PRAZO 1000000 1000005 5 510101 510104 4 510000 510067 4 510068 510100 3 1000006 10000010 5 810000 810001 5 810002 810003 5 810004 810005 5
Having this, how will I write a query or Procedure in Oracle that unite the records whose zip code bands with same term are considered "neighbors"?
Two CEP bands are considered to be "neighbours" when the CEP_FIM
of the first adding 1 is equal CEP_INICIO
of the second, eambas have the same deadline?
In the above case, the outcome of the proceedings would be:
CEP_INICIO CEP_FIM PRAZO 1000000 10000010 5 510101 510104 4 510000 510067 4 510068 510100 3 810000 810005 5
All right, all right, all right.
what you already have of code?
– rLinhares
This idea of neighboring zip code "+1" should not work, I believe, because it has neighboring intervals larger than one. Is there a guarantee that there are no overlapping bands? What is the purpose of this ? Reduce the number of records ? Only display in a query ?
– Motta
So, the neighboring intervals larger than one are of different tracks, the object proposed in this my doubt is to obtain in a single line the smallest and largest number of zip code of a band that is completed within the same period, as in the example: Cep 810000 goes up to 810005 in 3 bands of the same term. I’m cracking my head here but I can’t think of a solution to.
– Yves Gasana
But do you "dry" the table or just the query output ? Have you tried something like cep_inicio+1=cep_fim on Join ? I still do not understand the "problem" because the objective of the table is to calculate the term and I do not believe that the number of lines interferes much in this.
– Motta