plsql尝试使用数字变量(年)来查找会计年度

时间:2014-10-22 01:03:26

标签: sql date stored-procedures parameters 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;

1 个答案:

答案 0 :(得分:0)

您可以使用'to_date'和'add_months'函数来获得所需的结果。假设您的财政年度是01-Jul - > 30-Jun下面的代码将为您提供所需的内容。

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

如果您的财政年度日期不同,您需要调整传递给add_months的-6 / 6。