Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE OR REPLACE FUNCTION fundtrack.prc_report_0015(p_custodycd character varying, pv_tlid character varying, pv_tlname character varying, pv_language character varying)
- RETURNS SETOF refcursor
- LANGUAGE plpgsql
- AS $function$
- DECLARE
- ret refcursor; -- Declare cursor variables
- ref2 refcursor;
- v_logsctx text;
- v_logsbody text;
- v_exception text;
- l_frdate date;
- l_todate date;
- BEGIN
- v_logsctx := plog.init('prc_report_0015', 30, false, false, false);
- v_logsbody:= 'prc_report_0015: '
- ||', pv_tlid = ' || pv_tlid
- ||', pv_tlname = ' || pv_tlname
- ||', pv_language = ' || pv_language;
- v_logsctx := plog.setbeginsection(v_logsctx, v_logsbody);
- ret := 'ret';
- OPEN ret FOR
- select
- substr(cf.custodycd,1,1) as ac01,
- substr(cf.custodycd,2,1) as ac02,
- substr(cf.custodycd,3,1) as ac03,
- substr(cf.custodycd,4,1) as ac04,
- substr(cf.custodycd,5,1) as ac05,
- substr(cf.custodycd,6,1) as ac06,
- substr(cf.custodycd,7,1) as ac07,
- substr(cf.custodycd,8,1) as ac08,
- substr(cf.custodycd,9,1) as ac09,
- substr(cf.custodycd,10,1) as ac010,
- cf.custid,
- cf.custodycd,
- cf.fullname,
- cf.custtype,
- 'X' as custp,
- cf.sex,
- 'X' aS sextp,
- to_char( cf.birthdate,fn_systemnums('systemnums.c_date_format')) birthdate ,
- cf.idcode,
- to_char( cf.iddate,fn_systemnums('systemnums.c_date_format')) iddate,
- to_char( cf.idexpdated,fn_systemnums('systemnums.c_date_format')) idexpdated,
- cf.idplace,
- cf.tradingcode,
- cf.taxno,
- cf.regaddress,
- cf.address,
- ct.position,
- a1.cdcontent as country,
- cf.phone,
- cf.mobile,
- cf.email,
- cf.fax,
- cf.bankacc,
- cf.bankcode,
- c.brname as citybank,
- cf.fullname as bankacname,
- b.mbname as bankname,
- au.custname as au_custname,
- au.position as au_position,
- au.sex as au_sex,
- 'X' aS sex_au_tp,
- to_char( au.birthdate,fn_systemnums('systemnums.c_date_format')) as au_birthdate ,
- au.idcode as au_idcode,
- to_char( au.iddate,fn_systemnums('systemnums.c_date_format')) as au_iddate,
- au.idplace as au_idplace,
- au.regaddress as au_regaddress,
- au.address as au_address,
- a2.cdcontent as au_country,
- au.mobile as au_mobile,
- au.email as au_email,
- au.fax as au_fax,
- case when au.auth_all = 'Y' then 'X' else ' '
- end auth_all,
- case when au.auth_order = 'Y'
- and au.auth_all = 'Y' then ' '
- when au.auth_order = 'Y'
- and au.auth_all <> 'Y' then 'X'
- else ' '
- end auth_order,
- case when cf.rcv_email = 'Y' then 'X' else ' '
- end as rcv_email,
- case when cf.rcv_sms = 'Y' then 'X' else ' '
- end as rcv_sms ,
- case when cf.rcv_mail = 'Y' then 'X' else ' '
- end as rcv_mail,
- sg.signature
- From CFMAST cf
- left join cfauth au on cf.custid = au.custid
- left join allcode a1 on cf.country = a1.cdval
- and a1.cdtype = 'CF'
- and a1.cdname = 'COUNTRY'
- left join allcode a2 on au.country = a2.cdval
- and a2.cdtype = 'CF'
- and a2.cdname = 'COUNTRY'
- left join members b on cf.bankcode = b.mbcode
- left join brgrp c on cf.bankcode = c.mbid
- and cf.citybank = c.brid
- left join cfsign sg on cf.custid = sg.custid
- left join cfcontact ct
- on cf.custid = ct.custid
- where cf.custodycd = p_custodycd
- --and b.mbtype = 'Y';
- and sg.type = 'SIG';
- v_logsctx := plog.setEndsection(v_logsctx, 'SUCCESS');
- -- Open the first cursor
- RETURN NEXT ret; -- Return the cursor to the caller
- v_logsctx := plog.init('prc_report_0015', 30, false, false, false);
- v_logsbody:= 'prc_report_0015: '
- ||', pv_tlid = ' || pv_tlid
- ||', pv_tlname = ' || pv_tlname
- ||', pv_language = ' || pv_language;
- v_logsctx := plog.setbeginsection(v_logsctx, v_logsbody);
- ref2 := 'ref2';
- OPEN ref2 FOR
- select
- substr(cf.custodycd,1,1) as ac01,
- substr(cf.custodycd,2,1) as ac02,
- substr(cf.custodycd,3,1) as ac03,
- substr(cf.custodycd,4,1) as ac04,
- substr(cf.custodycd,5,1) as ac05,
- substr(cf.custodycd,6,1) as ac06,
- substr(cf.custodycd,7,1) as ac07,
- substr(cf.custodycd,8,1) as ac08,
- substr(cf.custodycd,9,1) as ac09,
- substr(cf.custodycd,10,1) as ac010,
- cf.custid,
- cf.custodycd,
- cf.fullname,
- cf.custtype,
- 'X' as custp,
- cf.sex,
- 'X' aS sextp,
- to_char( cf.birthdate,fn_systemnums('systemnums.c_date_format')) birthdate ,
- cf.idcode,
- to_char( cf.iddate,fn_systemnums('systemnums.c_date_format')) iddate,
- to_char( cf.idexpdated,fn_systemnums('systemnums.c_date_format')) idexpdated,
- cf.idplace,
- cf.tradingcode,
- cf.taxno,
- cf.regaddress,
- cf.address,
- ct.position,
- a1.cdcontent as country,
- cf.phone,
- cf.mobile,
- cf.email,
- cf.fax,
- cf.bankacc,
- cf.bankcode,
- c.brname as citybank,
- cf.fullname as bankacname,
- b.mbname as bankname,
- au.custname as au_custname,
- au.position as au_position,
- au.sex as au_sex,
- 'X' aS sex_au_tp,
- to_char( au.birthdate,fn_systemnums('systemnums.c_date_format')) as au_birthdate ,
- au.idcode as au_idcode,
- to_char( au.iddate,fn_systemnums('systemnums.c_date_format')) as au_iddate,
- au.idplace as au_idplace,
- au.regaddress as au_regaddress,
- au.address as au_address,
- a2.cdcontent as au_country,
- au.mobile as au_mobile,
- au.email as au_email,
- au.fax as au_fax,
- case when au.auth_all = 'Y' then 'X' else ' '
- end auth_all,
- case when au.auth_order = 'Y'
- and au.auth_all = 'Y' then ' '
- when au.auth_order = 'Y'
- and au.auth_all <> 'Y' then 'X'
- else ' '
- end auth_order,
- case when cf.rcv_email = 'Y' then 'X' else ' '
- end as rcv_email,
- case when cf.rcv_sms = 'Y' then 'X' else ' '
- end as rcv_sms ,
- case when cf.rcv_mail = 'Y' then 'X' else ' '
- end as rcv_mail,
- sg.signature
- From CFMAST cf
- left join cfauth au on cf.custid = au.custid
- left join allcode a1 on cf.country = a1.cdval
- and a1.cdtype = 'CF'
- and a1.cdname = 'COUNTRY'
- left join allcode a2 on au.country = a2.cdval
- and a2.cdtype = 'CF'
- and a2.cdname = 'COUNTRY'
- left join members b on cf.bankcode = b.mbcode
- left join brgrp c on cf.bankcode = c.mbid
- and cf.citybank = c.brid
- left join cfsign sg on cf.custid = sg.custid
- left join cfcontact ct
- on cf.custid = ct.custid
- where cf.custodycd = p_custodycd
- --and b.mbtype = 'Y';
- and sg.type = 'SIG'; -- Open the second cursor
- v_logsctx := plog.setEndsection(v_logsctx, 'SUCCESS');
- RETURN NEXT ref2; -- Return the cursor to the caller
- Exception
- when others then
- GET STACKED DIAGNOSTICS v_exception = PG_EXCEPTION_CONTEXT;
- v_logsbody := plog.setEndsection(v_logsctx,'prc_report_0015.Error:' || SQLERRM ||', SQLSTATE:'|| SQLSTATE
- ||', PG_EXCEPTION_CONTEXT:' || v_exception);
- OPEN ret FOR
- select 'Data not found' p_return;
- RETURN ;
- END;
- $function$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement