嗨,我已经创建了一个存储过程。当我使用它的时候speednte_no = 5 purun_kod = 2,3,1和ppolice_no = 6可以正常工作,但是当我不使用purun_kod的情况下使用pagente_no = 5且ppolice_no = 6不能正常工作时,我的意思是没有错误,只是无法打开响应。谢谢。
function police_ara(pacente_no in musteri_rol.musteri_rol_kod%type,
purun_kod in police.urun_kod%type,
ppolice_no in police.police_no%type,) return sys_refcursor is
vret sys_refcursor;
v_urun_kod varchar(1000);
begin
v_urun_kod := purun_kod;
open vret for
with policeler as
(select distinct
ph.police_hareket_id ph_police_hareket_id,
p.urun_kod,
(select max(pho.police_hareket_id) from police_hareket_otr pho
where pho.police_hareket_id = ph.police_hareket_id
and (pho.durum_kod1 = 0 or pho.durum_kod2 = 0 or pho.durum_kod3 = 0 or pho.durum_kod4 = 0)) pho_police_hareket_id,
ph.police_id,
from police p
inner join police_hareket ph
on ph.police_id = p.police_id
and (ph.ekbelge_no>0 or (select count(1)
from police_kotasyon pk
where pk.police_hareket_id = ph.police_hareket_id
and pk.kotasyon_seviyesi = 3
and rownum = 1)>0)
on (mr.musteri_rol_id = pa.acente_id)
left join ekbelge ek
on (ek.ekbelge_kod = ph.ekbelge_kod)
join (select regexp_substr(v_urun_kod, '[^,]+', 1, level) urun_kod
from dual
connect by level <= regexp_count(v_urun_kod, ',') + 1
) x on p.urun_kod = x.urun_kod
where (p.police_no = ppolice_no or ppolice_no is null)
and (p.pacente_no = pacente_no or pacente_no is null)
--and (p.urun_kod = purun_kod or purun_kod is null) ////THİS LİNEEE\\\\
select
urun_kod,
police_no,
from policeler
left join police_musteri pm_sg
on pm_sg.police_hareket_id = ph_police_hareket_id
and pm_sg.rol_id = pck_const_rol.sigortali
and pm_sg.sira_no = 1
left join musteri m_sg
on (m_sg.musteri_id = pm_sg.musteri_id)
return vret;
end;
答案 0 :(得分:1)
这是因为您在内部联接中使用了该值purun_kod:
...
join (select regexp_substr(v_urun_kod, '[^,]+', 1, level) urun_kod
from dual
connect by level <= regexp_count(v_urun_kod, ',') + 1
) x on p.urun_kod = x.urun_kod
...
如果不提供值,则内部联接将失败。
更新1
尝试更改与下一个的连接:
...
join (select regexp_substr(v_urun_kod, '[^,]+', 1, level) urun_kod
from dual
connect by level <= regexp_count(v_urun_kod, ',') + 1
) x on p.urun_kod = nvl(x.urun_kod,p.urun_kod)
...
我放置了一个NVL,因此,如果X.URUN_KOD列为空,则什么都不会发生。