语句查询特别慢,请问如何优化以下sql!


SELECT 
decode(b.flowid,'1610','销售','1650','销退') as flowname,
f8.deptname as ownername,
a.saledeptid,
f_get_rxstatus(a.id) as rxstatus,
f1.deptcode as deptcode,
f1.deptname as deptname,
a.createdate as createdate,
a.billno as grpno,
b.billno as billno,
b.goodid,f3.goods,
f3.goodstat,f3.msunitno,f3.name as goodsname,f3.spec,f3.producer,
(select name from pub_waredict_kind where kindid = f3.form) form,
(select name from pub_waredict_kind where type = '1500' and code = f3.opertype) opertype,
(select name from pub_waredict_kind where kindid = f3.otctype) otctype,
f3.prdlicense,
f3.register,
f3.ratifier,
f3.memo3,
f3.warebrand,
b.billqty,
f6.dname as prccstname,
b.price,
b.prc,
b.value,
b.sumvalue,
e.inprice,
e.inprc,
e.inprc*b.billqty as pcje,
b.offprc,
b.offvalue,
b.offsumvalue,
b.sumvalue-b.offsumvalue AS aftoffvalue,
b.value-b.offvalue AS zrhoffvalue,
(b.sumvalue-b.offsumvalue )-(b.value-b.offvalue) as zrhse,
decode((b.prc-b.offprc),0,0,ROUND((b.prc-b.offprc-e.inprc)/(b.prc-b.offprc),4)) as mll,
decode((b.sumvalue - b.offsumvalue),0,0,round((b.sumvalue - b.offsumvalue) - (b.billqty * e.inprc), 6)) AS hsml,
decode((b.sumvalue - b.offsumvalue),0,0,round((b.value - b.offvalue) - (b.billqty * e.inprice), 6)) AS wsml,
decode(b.value - b.offvalue,0,0, round((b.value - b.offvalue - (e.inprice * b.billqty)) / (b.value - b.offvalue),4)) kpivalue_profit,
decode(b.value - b.offvalue,0,0, round((b.sumvalue - b.offsumvalue - (e.inprc * b.billqty)) / (b.sumvalue - b.offsumvalue),4)) kpisumvalue_profit,
d.lotno,
e.batchno,
d.prddate,
d.enddate,
f7.empname as createusername,
b.taxrate,
f2.code as customcode,
f2.name as customname,
f2.tel,
f2.sex,
decode(f2.birthday,null,null,to_char(sysdate,'yyyy') -to_char(f2.birthday,'yyyy') ) as age,
F_GET_WAREOTCTYPE(b.compid,b.goodid,b.deptid) as WAREOTCTYPENAME,
a.rxno,
f5f1.code as hospitalcode,
f5f1.dname as hospitalname,
a.memo1,
a.sendaddr,
a.memo4,
a.INVCSTNAME,
a.Invcstaddress,
b.invoiceno,
b.INVOICEDATE,
b.INVOICEID,
decode(a.stopflag,'00','正常','90','被作废','99','作废',b.stopflag) AS stopflagname,
a.stopflag,
c.lotid,
c.batchid,
a.CUSTOMERID,
a.OWNERID,
zc.tel,
zc.doctor,
zc.section,
decode(a.tmsflag,'00','否','10','是',a.tmsflag) as tmsflagname,
a.rxid,
a.tmsflag,
decode(a.invpostflag,'00','立即开票','10','暂缓开票','20','发票信息待确认',a.invpostflag) as invpostflag,
decode(a.OPERATESTATUS1,'00','未确认','10','已确认',a.OPERATESTATUS1) as OPERATESTATUS1,
b.recheckdate,
a.gathdate,
(select min(x.createdate) from scm_bal_boa x where x.DEPTID=a.saledeptid and x.BALDAY=a.balday ) as baldate,
decode(F_GET_SALINV_GETHINFO(b.id),'10','未收款') gathinfo,
(select cstcode from pub_clients where cstid = e.cstid) gyscstcode,
(select dname from pub_clients where cstid = e.cstid) gysdname
from scm_salbill_grp a 
JOIN scm_salbill_hdr b ON a.id=b.grpid
JOIN scm_salbill_dtl c ON b.id=c.id
LEFT JOIN scm_lot_list_v d ON c.lotid=d.lotid AND b.goodid=d.goodid
LEFT JOIN scm_batch_list e ON c.batchid=e.batchid
JOIN pub_dept f1 ON b.compid=f1.compid AND b.deptid=f1.deptid
LEFT JOIN pub_rtlcustomer f2 ON a.compid=f2.compid AND a.customerid=f2.id
JOIN pub_waredict f3 ON a.compid=f3.compid AND b.goodid=f3.goodid
LEFT JOIN pub_rtlrx_hdr f5 ON a.compid=f5.compid AND a.rxid=f5.id
LEFT JOIN pub_rtlmtu f5f1 ON a.compid=f1.compid AND f5.mtuid=f5f1.id 
LEFT JOIN  pub_clients f6 ON a.compid=f6.compid AND b.prccstid=f6.cstid
LEFT JOIN  pub_emp f7 ON a.compid=f7.compid AND a.createuser=f7.empid
LEFT JOIN PUB_DEPT f8 on a.COMPID=f8.compid and a.OWNERID=f8.deptid
LEFT JOIN  USER_CHUFANGXINXI_V  zc on a.rxid= zc.id
 where 1=1 and b.flowid in ('1610','1650') AND  a.createdate>= SYSDATE-30

查询计划-点击清晰查看

img

搞个物化视图吧这么长的语句

请采纳