select
l_gist.id LineId
pp.SEQUENCIA Sequence,
pg.codigo StopCode,
pg.descricao StopDesc,
pp.espinha_publico Zone,
n.DESCRICAO NodeName,
to_char(null) PrevStopCode,
to_number(null) Distance,
pp.zona Zona, pp.limite_cidade LimiteCidade
from
lines l_gist,
td_linhas l,
td_percursos pc,
td_prc_prg pp,
td_paragens pg,
td_nosprgprc npp,
td_nos_rede n
where
l.codigo = l_gist.name and
pc.id_lnh = l.id and
pc.DT_INI <= :RefDate and
pp.id_prc = pc.id and
pg.codigo = pp.cod_prg and
npp.ID_PRC (+) = pp.ID_PRC and
npp.COD_PRG (+) = pp.COD_PRG and
:RefDate between npp.dt_ini (+) and nvl(npp.DT_FIM (+), :RefDate) and
not exists (
select 1
from td_nosprgprc npp2
where
npp2.id_prc = npp.id_prc and
npp2.sentido = npp.sentido and
npp2.cod_prg = npp.cod_prg and
:RefDate between npp2.dt_ini (+) and nvl(npp2.DT_FIM (+), :RefDate) and
npp2.DT_INI > npp.dt_ini
) and
n.ID (+) = npp.ID_NO and
pp.SEQUENCIA = 1
union
select
pp.SEQUENCIA,
pg.codigo,
pg.descricao,
pp.espinha_publico,
n.DESCRICAO,
pp_prev.COD_PRG,
s.DISTANCIA,
pp.zona Zona, pp.limite_cidade LimiteCidade
from
lines l_gist,
td_linhas l,
td_percursos pc,
td_prc_prg pp,
td_paragens pg,
td_nosprgprc npp,
td_nos_rede n,
td_prc_prg pp_prev,
td_segmentos s
where
l.codigo = l_gist.name and
pc.id_lnh = l.id and
pc.DT_INI <= :RefDate and
pp.id_prc = pc.id and
pg.codigo = pp.cod_prg and
npp.ID_PRC (+) = pp.ID_PRC and
npp.COD_PRG (+) = pp.COD_PRG and
:RefDate between npp.dt_ini (+) and nvl(npp.DT_FIM (+), :RefDate) and
not exists (
select 1
from td_nosprgprc npp2
where
npp2.id_prc = npp.id_prc and
npp2.sentido = npp.sentido and
npp2.cod_prg = npp.cod_prg and
:RefDate between npp2.dt_ini (+) and nvl(npp2.DT_FIM (+), :RefDate) and
npp2.DT_INI > npp.dt_ini
) and
n.ID (+) = npp.ID_NO and
pp_prev.id_prc (+) = pp.id_prc and
pp_prev.sequencia (+) = pp.SEQUENCIA-1 and
s.COD_PRG_INI = pp_prev.COD_PRG and
s.COD_PRG_FIM = pg.CODIGO
union
select
pp_h.SEQUENCIA,
pg.codigo,
pg.descricao,
pp_h.espinha_publico,
n.DESCRICAO,
to_char(null),
to_number(null),
pp_h.zona Zona, pp_h.limite_cidade LimiteCidade
from
lines l_gist,
td_linhas l,
td_percursos pc,
th_percursos pc_h,
th_prc_prg pp_h,
td_paragens pg,
td_nosprgprc npp,
td_nos_rede n
where
l.codigo = l_gist.name and
pc.id_lnh = l.id and
pc_h.ID_PRC = pc.id and
:RefDate between pc_h.DT_INI and pc_h.dt_fim and
pp_h.ID_H_PRC = pc_h.id and
pg.codigo = pp_h.cod_prg and
npp.ID_PRC (+) = pp_h.ID_PRC and
npp.SENTIDO (+) = :RouteOrientation and
npp.COD_PRG (+) = pp_h.COD_PRG and
:RefDate between npp.dt_ini (+) and nvl(npp.DT_FIM (+), :RefDate) and
not exists (
select 1
from td_nosprgprc npp2
where
npp2.id_prc = npp.id_prc and
npp2.sentido = npp.sentido and
npp2.cod_prg = npp.cod_prg and
:RefDate between npp2.dt_ini (+) and nvl(npp2.DT_FIM (+), :RefDate) and
npp2.DT_INI > npp.dt_ini
) and
n.ID (+) = npp.ID_NO and
pp_h.SEQUENCIA = 1
union
select
pp_h.SEQUENCIA,
pg.codigo,
pg.descricao,
pp_h.espinha_publico,
n.DESCRICAO,
pp_h_prev.COD_PRG,
s.DISTANCIA,
pp_h.zona Zona, pp_h.limite_cidade LimiteCidade
from
lines l_gist,
td_linhas l,
td_percursos pc,
th_percursos pc_h,
th_prc_prg pp_h,
td_paragens pg,
td_nosprgprc npp,
td_nos_rede n,
th_prc_prg pp_h_prev,
td_segmentos s
where
l.codigo = l_gist.name and
pc.id_lnh = l.id and
pc_h.ID_PRC = pc.id and
:RefDate between pc_h.DT_INI and pc_h.dt_fim and
pp_h.ID_H_PRC = pc_h.id and
pp_h.SENTIDO = :RouteOrientation and
pg.codigo = pp_h.cod_prg and
npp.ID_PRC (+) = pp_h.ID_PRC and
npp.SENTIDO (+) = :RouteOrientation and
npp.COD_PRG (+) = pp_h.COD_PRG and
:RefDate between npp.dt_ini (+) and nvl(npp.DT_FIM (+), :RefDate) and
not exists (
select 1
from td_nosprgprc npp2
where
npp2.id_prc = npp.id_prc and
npp2.sentido = npp.sentido and
npp2.cod_prg = npp.cod_prg and
:RefDate between npp2.dt_ini (+) and nvl(npp2.DT_FIM (+), :RefDate) and
npp2.DT_INI > npp.dt_ini
) and
n.ID (+) = npp.ID_NO and
pp_h_prev.id_h_prc (+) = pp_h.id_h_prc and
pp_h_prev.sequencia (+) = pp_h.SEQUENCIA-1 and
s.COD_PRG_INI = pp_h_prev.COD_PRG and
s.COD_PRG_FIM = pg.CODIGO";
Tuesday, 19 May 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment