2014-10-22 78 views
0

感謝您的幫助,PLSQL試圖用數字變量(年)發現財政年度

我想建立一個存儲過程,在PL/SQL,在那裏我可以從指定的會計年度加載數據。

例如,fyloader(2013)將在10/01/2012至09/30/2013之間加載pe.contact_date。我怎樣才能做到這一點?

再次感謝您, 威爾

create or replace procedure fyloader (
    p_fiscal_year   number 
) as 

begin 

    insert into schemax.tablex 
    (select distinct pe.pat_id as PATID, 
    pat.pat_mrn_id as PATMRNID, 
    pe.pcp_prov_id as PCPPROVID, 
    pe.department_id as DEPARTMENTID, 
    pe.contact_date as CONTACTDATE, 
    trunc((TO_DATE ('30-09-2013 23:59:59', 'DD-MM-YYYY HH24:MI:SS') - pat.birth_date)/365.25) AS AGE, 
    '' as AGEGROUP, 
    ce.financial_class as FINCLASS 
    from pat_enc pe 
    inner join patient pat on pe.pat_id = pat.pat_id 
    inner join clarity_dep b on b.department_id = pe.department_id 
    left join clarity_ser cs on pe.visit_prov_id = cs.prov_id 
    left join zc_def_division zc on cs.def_division_c = zc.def_division_c 
    inner join hsp_account ha on pe.hsp_account_id = ha.hsp_account_id 
    inner join clarity_epm ce on ha.primary_payor_id = ce.payor_id 
    where 
    pe.enc_type_c = '101' --include office visits only (add 1001 if you require VirVis) 
    and (pe.appt_status_c = 2 OR pe.appt_status_c is null) 
    and (pat.pat_status_c =1 or nvl(pat.pat_status_c,99999) = 99999) 
    and pe.contact_date between TO_DATE('1-OCT-2012','DD-MON-YY') and TO_DATE('30-SEP-2013','DD-MON-YY') 
    and (zc.def_division_c in (26,91,266,329,330,331,332,333,389,402) 
    or pe.visit_prov_id = pe.pcp_prov_id) 
    and ce.financial_class in ('1','3') 
    and b.DEPARTMENT_ID in (200101,200102,200104,200201,200202,200204, 
    200220,200301,200302,200304,200319,200401,200402,200404,200501,200601, 
    200602,200701,200702,200704,200801,200802,200804,200911,200912,200913, 
    200914,200916,200917,200921,200923,200924,200925,200926,200927,200928, 
    201002,201201,201202,202101,202102,202104,202108,202301,202302,202308, 
    234005,230407,290109)); 
    commit; 

end; 

回答

0

您可以使用「TO_DATE」和「ADD_MONTHS」功能,以獲得您所需要的結果。假設你的財政年度是7月1日 - > 6月30日,下面的代碼會給你你想要的。

declare 
    p_input_year number := 2014; 
    v_fy_start_date date; 
    v_fy_end_date date; 
begin 
    v_fy_start_date := add_months(to_date('0101'||p_input_year,'DDMMYYYY'), -6); 
    v_fy_end_date := add_months(to_date('0101'||p_input_year,'DDMMYYYY'), 6) - 1; 

    dbms_output.put_line('FY Start: ' || v_fy_start_date); 
    dbms_output.put_line('FY End: ' || v_fy_end_date); 

end; 

DBMS_OUTPUT之中的結果:

FY Start: 01-JUL-13 
FY End: 30-JUN-14 

如果您的財政年度日期不同,您將需要調整-6/6傳遞給ADD_MONTHS。

+0

完美的幫助,謝謝! – 2014-10-22 14:55:44

相關問題