CREATE OR REPLACE function sd_hospital.sf_xt_csrqtonl_bz( Pcsrq00 char, Pcssj00 char default '00:00:00', Pjzrq00 char default to_char(sysdate,'yyyymmdd'), Pjzsj00 char default '00:00:00', Pfhgs00 char default '2' --返回格式:'0'标准;'1'岁月天;'2'YMD;'3'标准(1-3岁去掉月份) ) return varchar2 is Vcsrqsj date; Vjzrqsj Date; Vresult varchar2(50); Vyear00 number(10); Vmonth0 number(10); Vday000 number(10); Vday001 number(12,4); Vcount char(10); -- MODIFICATION HISTORY -- Person Date Comments -- zhanghr 2019.11.15 统一年龄的计算办法 create BQHS9.0-20191115-004 -- zouqc 2020.06.03 对漳浦妇幼年龄算法特殊操作 for ZYDZBL-20200330-002 begin if Pjzrq00 is null then Vjzrqsj:=sysdate; else Vjzrqsj:=to_date(Pjzrq00||Pjzsj00,'yyyymmddhh24:mi:ss'); end if; if Pcsrq00 is null then return '不详'; else begin Vcsrqsj:=to_date(Pcsrq00||Pcssj00,'yyyymmddhh24:mi:ss'); exception when others then return '不详'; end; end if; Vyear00:=trunc(months_between(Vjzrqsj,Vcsrqsj)/12); Vmonth0:=mod(trunc(months_between( Vjzrqsj,Vcsrqsj)),12); Vday000:=trunc(Vjzrqsj-add_months(Vcsrqsj,Vyear00*12+Vmonth0)); Vday001:=Vjzrqsj-Vcsrqsj; select count(1) into Vcount from XT_YYXX00 where YYID00='226523';--判断是否漳浦妇幼 if Pfhgs00 in ('0','3') then --2016 病历规范关于年龄的定义:患者出生时间,在0-72小时的,记录到小时;72小时-1周岁的,记录到 月份和天数; 1-3周岁的,记录到岁和月; --3岁以上记录到岁。出生日为第0天。按按照日历计算的历法年龄,实足年龄。 -- >3周岁 if Vyear00>=3 then return to_char(Vyear00)||'岁'; -- 1-3周岁 elsif Vyear00>=1 and Vyear00<3 then if Pfhgs00='0' then return to_char(Vyear00)||'岁'||to_char(Vmonth0)||'月'; elsif Pfhgs00='3' then return to_char(Vyear00)||'岁'; end if; -- <72小时 elsif Vday001*24>=0 and Vday001*24<72 then return to_char(trunc(Vday001*24))||'小时'; --72小时-1周岁 elsif Vday001*24>=72 and Vyear00<1 then if vcount=0 then if Vmonth0>0 then return to_char(Vmonth0)||'月'||to_char(Vday000)||'天'; else return to_char(Vday000)||'天'; end if; else if Vmonth0>0 then return to_char(Vmonth0)||'月'||to_char(Vday000)||'天'; else return to_char(Vday000)||'天'; end if; end if; else return '不详'; end if; elsif Pfhgs00='1' then if Vyear00>=5 then return to_char(Vyear00)||'岁'; elsif Vday001>=0 and Vyear00<5 then if vcount=0 then return to_char(Vyear00)||'岁'||to_char(Vmonth0)||'月'||to_char(Vday000)||'天'; else return to_char(Vyear00)||'岁'||to_char(Vmonth0)||'月'||to_char(Vday000)||'天'; end if; else return '不详'; end if; elsif Pfhgs00='2' then if Vyear00>=5 then return to_char(Vyear00)||'Y'; elsif Vday001>=0 and Vyear00<5 then return to_char(Vyear00)||'Y'||to_char(Vmonth0)||'M'||to_char(Vday000)||'D'; else return '--'; end if; else return '不详'; end if; end; /