select paginado.* from (
select rownum rn, antecedenteComprobacionTabs.* from (select decode(porintv, null, 0, 1) + decode(pormat, null, 0, 1) + decode(porcls, null, 0, 1) + decode(porproj, null, 0, 1) + decode(porprojori, null, 0, 1) as sumcoincidencias,
antecedenteRecuperado.* from (select datos.* from (select
idcondrptanteced,
idasunto,
cdprojori,
nmprorgjudori,
nmprorgjuddest,
cdtipoprojori,
cdtipoprojdest,
cdestadoregistro,
itasuntoenmovimiento,
cdufojactual,
dsufojactual,
cdufojrpt,
dsufojrpt,
cdtipoasunto,
nmregistroofre,
anyoregistroofre,
cdtipoprojoriext,
numprojoriext,
anyoprojoriext,
itsecretosumario,
cdufojactualDestinoCLS,
cdufojrptDestinoCLS,
cdufojori,
replace(replace(xmlagg
(xmlelement (e, nombreintv,'|',itrol,'|',cdtipointvproj,'*',cdclsrpt,'*',
cdtipodelimate,'|',cdfamidelimate,'|',dstipodelimate,'*',
cdtipoproj,'|',dstipoproj,'*',cdprojori,'*')),'',''),'','') as datosAntecedentes,
replace(replace(xmlagg
(xmlelement (e, decode(nombreintv, null, null, 1))),' ',''),'','') as porintv,
replace(replace(xmlagg
(xmlelement (e, decode(cdtipodelimate, null, null, 1))),' ',''),'','') as pormat,
replace(replace(xmlagg
(xmlelement (e, decode(cdclsrpt, null, null, 1))),' ',''),'','') as porcls,
replace(replace(xmlagg
(xmlelement (e, decode(cdtipoproj, null, null, 1))),' ',''),'','') as porproj,
replace(replace(xmlagg
(xmlelement (e, decode(cdprojori, null, null, decode(cdprojori, '/', null, 1)))),' ',''),'','') as porprojori,
prioridad,
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_intv intva where cond.idcondrpt = :idcondrpt and INTVA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and intva.fcbaja is null and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_clsreparto clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_materia clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_projori clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and clsa.itprojori = 'S' and prioridadcomparar = cond.prioridad) +
(select decode(count(*), 0, 0, 1) from ofre_condrptanteced cond, ofre_condrptanteced_tipoproj clsa where cond.idcondrpt = :idcondrpt and clsA.IDCONDRPTANTECED = cond.idcondrptanteced and cond.fcbaja is null and clsa.fcbaja is null and prioridadcomparar = cond.prioridad) con
from
(
SELECT
prioridad as prioridadcomparar,
idcondrptanteced,
asuant.idasunto,
antecedente.cdufojori || antecedente.cdtipoprojori || antecedente.nmprorgjudori || '/' || antecedente.anyoprorgjudori cdprojori,
-- rownum rn,
lpad(antecedente.nmprorgjudori, 7, '0') || '/' || antecedente.anyoprorgjudori nmprorgjudori,
lpad(pjdest.NMPRORGJUD, 7, '0') || '/' || pjdest.anyoPRORGJUD nmprorgjuddest,
asuant.cdtipoprojori cdtipoprojori,
pjdest.cdtipoproj cdtipoprojdest,
aufoj.cdestadoregistro, -- 'ENV' o 'REP'
asuant.itasuntoenmovimiento, -- 'S' o 'N'
asuant.cdufojactual,
(SELECT UF.DSUFOJ FROM INTS_C_UFORGJUDICIAL UF
WHERE UF.CDUFOJ = asuant.cdufojactual) as dsufojactual,
asuant.cdufojrpt,
(SELECT UF.DSUFOJ FROM INTS_C_UFORGJUDICIAL UF
WHERE UF.CDUFOJ = asuant.cdufojrpt) as dsufojrpt,
asuant.cdtipoasunto, asuant.nmregistroofre, asuant.anyoregistroofre,
asuant.cdtipoprojoriext, asuant.numprojoriext, asuant.anyoprojoriext,
(select nvl(
(select 'S' from dual
where
((sysdate between asuant.FCINISECRETOACT and asuant.FCFINSECRETOACT)
or (asuant.FCINISECRETOACT < idverclsrpt =" des.idverclsrpt" idasunto =" :idasunto" idverclsrpt =" des.idverclsrpt" idasunto =" :idasunto" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" idasunto =" :idasunto" itprojori =" 'S'" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" idconfigreparto =" antcls.cdconfigreparto" idconfigreparto =" antcls.cdconfigreparto" idclsrpt =" CONF.IDCLSRPT" idcondrpt =" :idcondrpt" cdinterviniente =" intv.cdinterviniente" cdintvasunto =" INTV.CDINTVASUNTO" idcondrptanteced =" antintv.idcondrptanteced" idasunto =" :idasunto" cdtipointvproj =" tipointvproj.cdtipointvproj" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" cdfamidelimate =" antmat.cdfamidelimate" cdtipodelimate =" antmat.cdtipodelimate" idcondrpt =" ant.idcondrpt" idcondrpt =" :idcondrpt" idcondrptanteced =" ant.idcondrptanteced" cdtipoproj =" ANTTIP.CDTIPOPROJ" cdufoj =" asuant.cdufojactual" idasunto =" asuant.idasunto"> 'ANU')
and pjdest.idasunto (+) = asuant.idasunto
AND (:idasuntofiltro = asuant.idasunto or (
-- búsqueda de antecedentes sin idasuntofiltro
:idasuntofiltro is null
-- El asunto a repartir no puede ser antecedente
and asuant.idasunto <> :idasunto
-- Exenciones de reparto
and not exists (
select
*
from
OFRE_INTVEXENRPT exen,
ints_asunto_intvasu intvasu
where
exen.cdufoj = :cdufojorr
AND exen.cdinterviniente = intvasu.cdinterviniente
AND intvasu.idasunto = asuant.idasunto
)
-- condiciones funcionales 09/2009 -- corregido 19/04/2010
and
exists (
select
cdufoj
from
OFRE_VERCLSREPARTO_DESTINO des,
ints_asunto asu
where
asu.idverclsrpt = des.idverclsrpt
and asu.idasunto = :idasunto
and (des.cdufoj = asuant.cdufojrpt
or des.cdufoj = asuant.cdufojactual
or (asuant.cdufojactual = :cdufojorr and asuant.cdufojrpt is null))
)
-- condicion de número de límite de registros
AND (antecedente.nmlimitereg is null --quitado idasuntofiltro
or antecedente.nmlimitereg = 0
or antecedente.diasvalidez is null
or antecedente.diasvalidez = 0
or antecedente.nmlimitereg >
(SELECT COUNT (*)
FROM ints_asunto asu
WHERE fcpresentacion > (SYSDATE - antecedente.diasvalidez)
and asu.cdufojrpt = asuant.cdufojrpt)
)
AND ( --dias de validez
(antecedente.diasvalidez is null
or antecedente.diasvalidez = 0
or
antecedente.diasvalidez > (SYSDATE - asuant.fcpresentacion))
AND
(
(
--Buscamos los intervinientes con el mismo tipo de intervención
EXISTS (
SELECT *
FROM
ints_asunto_intvasu intv,
INTS_C_TIPOINTVPROJ ipro
WHERE
intv.fcbaja IS NULL
and ipro.cdtipointvproj = intv.cdtipointvproj
and intv.cdinterviniente = antecedente.cdinterviniente
and intv.idasunto = asuant.idasunto
and
-- se busca la coincidencia del criterio en el asunto a repartir
(
(itasuntoregistro is null or itasuntoregistro = 'N')
or
(
(antecedente.cdtipointvprojasu = antecedente.cdtipointvproj or antecedente.cdtipointvproj is null)
and
(antecedente.itrolasu = antecedente.itrol or antecedente.itrol is null)
)
)
and
-- se busca la coincidencia del criterio en el antecedente
(
(itasuntoantecedente is null or itasuntoantecedente = 'N')
or
(
(intv.cdtipointvproj = antecedente.cdtipointvproj or antecedente.cdtipointvproj is null)
and
(ipro.itrol = antecedente.itrol or antecedente.itrol is null)
)
)
)
)-- fin OR de tipo de intervención
OR (
-- antecedentes por materia
asuant.cdfamidelimate = antecedente.cdfamidelimate and antecedente.cdtipodelimate is null
or asuant.cdtipodelimate = antecedente.cdtipodelimate and antecedente.cdfamidelimate is null
or asuant.cdfamidelimate = antecedente.cdfamidelimate and asuant.cdtipodelimate = antecedente.cdtipodelimate
)
OR (-- por tipo de procedimiento
pjdest.cdtipoproj = antecedente.cdtipoproj
)
OR (
-- por clase de reparto
asuant.idverclsrpt = antecedente.idverclsrpt
)
OR (
-- por procedimiento origen
asuant.idasuntoori = antecedente.idasuntoori
or
asuant.cdufojori = antecedente.cdufojori
and asuant.cdtipoprojori = antecedente.cdtipoprojori
and asuant.nmprorgjudori = antecedente.nmprorgjudori
and asuant.anyoprorgjudori = antecedente.anyoprorgjudori
)
)
)
) )
) group by
prioridad,
idcondrptanteced,
idasunto,
cdprojori,
nmprorgjudori,
nmprorgjuddest,
cdtipoprojori,
cdtipoprojdest,
cdestadoregistro,
itasuntoenmovimiento,
cdufojactual,
dsufojactual,
cdufojrpt,
dsufojrpt,
cdtipoasunto,
nmregistroofre,
anyoregistroofre,
cdtipoprojoriext,
numprojoriext,
anyoprojoriext,
itsecretosumario,
cdufojactualDestinoCLS,
cdufojrptDestinoCLS,
cdufojori
) datos ) antecedenteRecuperado
) antecedenteComprobacionTabs
where sumcoincidencias = con
) paginado
where rn between :inicio and decode(:idasuntofiltro, null, :fin, 1)
¡Cómo crece mi hija!
Qué mal de padre que tiene que nadie se atreve a mirarla que no sea yo...