CREATE OR REPLACE FUNCTION SF_ZH_YDYPXZ ( PBRID00 in number,--病人ID PDJH000 in number,--单据号 PYSBM00 in number,--医生编码 PKSBM00 in number,--科室编码 PXMBH00 in number,--项目编号 PYPXZ00 in number,--药品性质 1基本用药 2临时用处方药 3临时用非处方药 4非基本药物 PTJFS00 in number default 0, --0:科室 1:科室,医生 2: 医生 科室 PMZZYBZ in number default 0 --0:门诊 1:住院 ) return number is Vreturn number(12,2); VCFHJJE number(12,2); VYZHJJE number(12,2); ZH_MZRBSFXSXCCYF varchar2(100); -- MODIFICATION HISTORY --Person Date Comment --zhangyc 2015.11.25 create by ZHCX-20151123-002 begin begin select trim(Value0) into ZH_MZRBSFXSXCCYF from xt_xtcs00 where name00='ZH_MZRBSFXSXCCYF'; exception when others then ZH_MZRBSFXSXCCYF:='N'; end; VCFHJJE:=0; VYZHJJE:=0; if ZH_MZRBSFXSXCCYF='Y' then if PMZZYBZ=0 then --门诊 if PXMBH00>=9999999990 then begin select Round(sum(round(C.LSDJ00*C.YPZSL0*100)/100),2)into VCFHJJE from SF_BRFY00 A,yf_mzcf00 B,yf_mzcfmx C,BM_YD0000 D,BM_YPLB00 E where A.DJH000=B.DJH000 and B.cflsh0 = C.cflsh0 and c.YPNM00=D.YPNM00 and A.BRID00=PBRID00 and A.DJH000=PDJH000 and (( PYPXZ00 ='1' and ypxz00 in('1','2')) or (ypxz00=PYPXZ00)) and d.lbbh00=e.lbbh00 and e.SFDM00=PXMBH00 and ( (PTJFS00 in (0) and A.DJH000 in (select DJH000 from sf_fymx00 aa where aa.XMBH00=PXMBH00 and aa.DJH000=PDJH000 and aa.KDKS00=PKSBM00)) or (PTJFS00 in (1,2) and A.DJH000 in (select DJH000 from sf_fymx00 aa where aa.XMBH00=PXMBH00 and aa.DJH000=PDJH000 and aa.KDYS00=PYSBM00 and aa.KDKS00=PKSBM00)) ); exception when others then VCFHJJE:=0; end; end if; else --住院 begin select Round(SUM(round(C.LSDJ00*C.YPZSL0*100)/100),2)into VCFHJJE from ZY_BRFY00 A,YF_ZYCF00 B,YF_ZYCFMX C,BM_YD0000 D where a.DJH000=B.DJH000 and B.cflsh0 = C.cflsh0 and c.YPNM00=D.YPNM00 and a.ZYID00=PBRID00 and D.YPXZ00=PYPXZ00; exception when others then VCFHJJE:=0; end; begin select Round(SUM(round(C.YPZSL0*C.LSDJ00*100)/100),2)into VYZHJJE from ZY_BRFY00 A,YF_YZYPSQ C,BM_YD0000 D where a.DJH000=C.DJH000 and c.YPNM00=D.YPNM00 and A.ZYID00=PBRID00 and D.YPXZ00=PYPXZ00; exception when others then VYZHJJE:=0; end; end if; end if; Vreturn:=nvl(VCFHJJE,0)+nvl(VYZHJJE,0); return nvl(Vreturn,0); end; /