1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| procedure ps_call_product_state(ICallListCursor out GenericCursor) is
cursor cState is
select PK_STATE, LABEL
from HDCALLSTAT
where HDCALLSTAT.ACTIVE = 'O'
order by HDCALLSTAT.CALL_ORDER;
num_pk_state HDCALLSTAT.PK_STATE%TYPE;
str_label HDCALLSTAT.LABEL%TYPE;
str_requete varchar2(2000);
BEGIN
str_requete := 'select HDPRODUCT.PRODUCT_NAME,';
open cState;
loop
fetch cState into num_pk_state,str_label;
Exit When cState%NOTFOUND ; -- sortie lorsque le curseur ne ramène plus de ligne
str_requete := str_requete||' sum(decode(FK_STATE,'||num_pk_state||',1,0)) "'||str_label||'",';
End loop ;
str_requete := str_requete||'count(FK_PRODUCT) "Total" ';
str_requete := str_requete||'from HDCALL,HDPRODUCT ';
str_requete := str_requete||'where HDCALL.FK_PRODUCT = HDPRODUCT.PK_PRODUCT ';
str_requete := str_requete||'group by HDPRODUCT.PRODUCT_NAME ';
execute immediate 'alter session set cursor_sharing=force';
open ICallListCursor for str_requete;
execute immediate 'alter session set cursor_sharing=exact';
exception
when others then
pck_log.PS_LOG_ERROR (c_pckname || '. ps_call_product_state',sqlcode, sqlerrm);
raise_application_error(-20000,sqlerrm);
END ps_call_product_state; |