/* 使用说明:直接查询ODRD121_RETAPPLYD_REPORTS_VIEW该视图,可以得到需求数据 设置存储过程定时说明: 对odrd121_retapplyd_reports存储过程制定晚上2点自动执行脚本,可以根据项目的需求进行相应的调整,参考如下: begin sys.dbms_job.submit(job => :job, what => 'odrd121_retapplyd_reports;', next_date => to_date('04-09-2009 02:00:00', 'dd-mm-yyyy hh24:mi:ss'), interval => 'trunc(sysdate)+1+2/24'); commit; end; 注意:创建后请不要再对物化视图进行刷新操作,由于odrd121_retapplyd_reports存储过程里已经对物化视图进行相关刷新操作, 如有需要可做相应的调整。 */ --临时表ODRD121_RETAPPLYD_REPORT创建 create table ODRD121_RETAPPLYD_REPORT ( ODRD121_ODRWAY_1 CHAR(2) not null, ODRD121_ORGID_2 VARCHAR2(13) not null, ODRD121_ODRDATE_3 CHAR(8) not null, ODRD121_STFID_4 VARCHAR2(13) not null, ODRD121_ORDERNO_5 VARCHAR2(18) not null, ODRD121_LINENO_6 NUMBER(6) not null, ODRD121_ITEMID_7 VARCHAR2(13) not null, ODRD121_PLUCD_8 VARCHAR2(13) not null, ODRD121_SPEC_9 NUMBER(10) not null, ODRD121_TRIP_10 CHAR(1) not null, ODRD121_PACKQTY_11 NUMBER(14,4) not null, ODRD121_UNITQTY_12 NUMBER(14,4) not null, ODRD121_ENTDATE_13 CHAR(14) not null, ODRD121_RETREASONID_14 CHAR(2) not null, ODRD121_GENDATE_15 CHAR(14) not null, ODRD121_HQPACKQTY_16 NUMBER(14,4) not null, ODRD121_HQUNITQTY_17 NUMBER(14,4) not null, ODRD121_CHKFLG_18 CHAR(1) not null, ODRD121_CHKSTFID_19 VARCHAR2(13) not null, ODRD121_CHKDATE_20 CHAR(14) not null, ODRD121_SNDFLG_21 CHAR(1) not null, ODRD121_SNDDATE_22 CHAR(14) not null, ODRD121_HEADFLG_23 CHAR(1) not null, ODRIM150_ITEMID_24 VARCHAR2(13) not null, ODRIM150_PLUCD_25 VARCHAR2(13) not null, ODRIM150_ITEMCNM_26 VARCHAR2(60) not null, VODRIM163_ITEMID_27 VARCHAR2(13) not null, VODRIM163_DLVRID_28 VARCHAR2(13) not null, VODRIM163_SPEC_29 NUMBER(10) not null, VODRIM163_SDATE_30 VARCHAR2(8) not null, VODRIM163_UNIT_31 VARCHAR2(4), ODRIM910_URTLGRS_32 NUMBER(14,4) not null, ODRIM910_URTLNET_33 NUMBER(14,4) not null, ODRIP011_ITEMID_34 VARCHAR2(13) not null, ODRIP011_ORGID_35 VARCHAR2(13) not null, ODRIP011_QTY_36 NUMBER(14,4) not null, ODRIM210_DLVRID_37 VARCHAR2(13) not null, ODRIM210_DLVRCD_38 VARCHAR2(8) not null, ODRIM210_DLVRCNM_39 VARCHAR2(50) not null, ODRIM080_STRID_40 VARCHAR2(13) not null, ODRIM080_STRCD_41 VARCHAR2(8) not null, ODRIM080_SVID_42 VARCHAR2(13) not null, ODRIM080_ORGID_43 VARCHAR2(13) not null, ODRIM080_STRCNM_44 VARCHAR2(40) not null, ODRIM013_SVID_45 VARCHAR2(13) not null, ODRIM013_SVCD_46 VARCHAR2(7) not null, ODRIM013_DOID_47 VARCHAR2(13) not null, ODRIM012_DOID_48 VARCHAR2(13) not null, ODRIM012_DOCD_49 VARCHAR2(4) not null, ODRIM161_ITEMID_50 VARCHAR2(13) not null, ODRIM161_DLVRID_51 VARCHAR2(13) not null, ODRIS020_PARACD_52 VARCHAR2(13) not null, ODRIS020_PARAVALUE_53 VARCHAR2(60) not null ); --ODRD121_RETAPPLYD_REPORTS存储过程创建 CREATE OR REPLACE PROCEDURE ODRD121_RETAPPLYD_REPORTS IS itmid ODRD121_RETAPPLYD.ODRD121_ITEMID%TYPE; timidcount number; CURSOR GetStrView IS SELECT DISTINCT ODRD121_ITEMID FROM ODRD121_RETAPPLYD; BEGIN timidcount := 0; OPEN GetStrView; LOOP FETCH GetStrView INTO itmid; EXIT WHEN GetStrView%NOTFOUND; IF TRIM(itmid) IS NOT NULL THEN --通过动态查询,把查询结果存放到ODRD121_RETAPPLYD_REPORT临时表里 EXECUTE IMMEDIATE ' INSERT /*+ APPEND*/ INTO ODRD121_RETAPPLYD_REPORT SELECT /*+ STAR */ ODRD121_RETAPPLYD.ODRD121_ODRWAY AS ODRD121_ODRWAY_1, ODRD121_RETAPPLYD.ODRD121_ORGID AS ODRD121_ORGID_2, ODRD121_RETAPPLYD.ODRD121_ODRDATE AS ODRD121_ODRDATE_3, ODRD121_RETAPPLYD.ODRD121_STFID AS ODRD121_STFID_4, ODRD121_RETAPPLYD.ODRD121_ORDERNO AS ODRD121_ORDERNO_5, ODRD121_RETAPPLYD.ODRD121_LINENO AS ODRD121_LINENO_6, ODRD121_RETAPPLYD.ODRD121_ITEMID AS ODRD121_ITEMID_7, ODRD121_RETAPPLYD.ODRD121_PLUCD AS ODRD121_PLUCD_8, ODRD121_RETAPPLYD.ODRD121_SPEC AS ODRD121_SPEC_9, ODRD121_RETAPPLYD.ODRD121_TRIP AS ODRD121_TRIP_10, ODRD121_RETAPPLYD.ODRD121_PACKQTY AS ODRD121_PACKQTY_11, ODRD121_RETAPPLYD.ODRD121_UNITQTY AS ODRD121_UNITQTY_12, ODRD121_RETAPPLYD.ODRD121_ENTDATE AS ODRD121_ENTDATE_13, ODRD121_RETAPPLYD.ODRD121_RETREASONID AS ODRD121_RETREASONID_14, ODRD121_RETAPPLYD.ODRD121_GENDATE AS ODRD121_GENDATE_15, ODRD121_RETAPPLYD.ODRD121_HQPACKQTY AS ODRD121_HQPACKQTY_16, ODRD121_RETAPPLYD.ODRD121_HQUNITQTY AS ODRD121_HQUNITQTY_17, ODRD121_RETAPPLYD.ODRD121_CHKFLG AS ODRD121_CHKFLG_18, ODRD121_RETAPPLYD.ODRD121_CHKSTFID AS ODRD121_CHKSTFID_19, ODRD121_RETAPPLYD.ODRD121_CHKDATE AS ODRD121_CHKDATE_20, ODRD121_RETAPPLYD.ODRD121_SNDFLG AS ODRD121_SNDFLG_21, ODRD121_RETAPPLYD.ODRD121_SNDDATE AS ODRD121_SNDDATE_22, ODRD121_RETAPPLYD.ODRD121_HEADFLG AS ODRD121_HEADFLG_23, ODRIM150_ITEM.ODRIM150_ITEMID AS ODRIM150_ITEMID_24, ODRIM150_ITEM.ODRIM150_PLUCD AS ODRIM150_PLUCD_25, ODRIM150_ITEM.ODRIM150_ITEMCNM AS ODRIM150_ITEMCNM_26, VODRIM163_ITEMCOST.VODRIM163_ITEMID AS VODRIM163_ITEMID_27, VODRIM163_ITEMCOST.VODRIM163_DLVRID AS VODRIM163_DLVRID_28, VODRIM163_ITEMCOST.VODRIM163_SPEC AS VODRIM163_SPEC_29, VODRIM163_ITEMCOST.VODRIM163_SDATE AS VODRIM163_SDATE_30, VODRIM163_ITEMCOST.VODRIM163_UNIT AS VODRIM163_UNIT_31, ODRIM910_STOREURTL.ODRIM910_URTLGRS AS ODRIM910_URTLGRS_32, ODRIM910_STOREURTL.ODRIM910_URTLNET AS ODRIM910_URTLNET_33, ODRIP011_STOCK.ODRIP011_ITEMID AS ODRIP011_ITEMID_34, ODRIP011_STOCK.ODRIP011_ORGID AS ODRIP011_ORGID_35, ODRIP011_STOCK.ODRIP011_QTY AS ODRIP011_QTY_36, ODRIM210_DELIVERER.ODRIM210_DLVRID AS ODRIM210_DLVRID_37, ODRIM210_DELIVERER.ODRIM210_DLVRCD AS ODRIM210_DLVRCD_38, ODRIM210_DELIVERER.ODRIM210_DLVRCNM AS ODRIM210_DLVRCNM_39, ODRIM080_STORE.ODRIM080_STRID AS ODRIM080_STRID_40, ODRIM080_STORE.ODRIM080_STRCD AS ODRIM080_STRCD_41, ODRIM080_STORE.ODRIM080_SVID AS ODRIM080_SVID_42, ODRIM080_STORE.ODRIM080_ORGID AS ODRIM080_ORGID_43, ODRIM080_STORE.ODRIM080_STRCNM AS ODRIM080_STRCNM_44, ODRIM013_SV.ODRIM013_SVID AS ODRIM013_SVID_45, ODRIM013_SV.ODRIM013_SVCD AS ODRIM013_SVCD_46, ODRIM013_SV.ODRIM013_DOID AS ODRIM013_DOID_47, ODRIM012_DO.ODRIM012_DOID AS ODRIM012_DOID_48, ODRIM012_DO.ODRIM012_DOCD AS ODRIM012_DOCD_49, ODRIM161_ITEMDLV.ODRIM161_ITEMID AS ODRIM161_ITEMID_50, ODRIM161_ITEMDLV.ODRIM161_DLVRID AS ODRIM161_DLVRID_51, ODRIS020_PARA.ODRIS020_PARACD AS ODRIS020_PARACD_52, ODRIS020_PARA.ODRIS020_PARAVALUE AS ODRIS020_PARAVALUE_53 FROM (SELECT odrim163_itemid VODRIM163_ITEMID, odrim163_dlvrid VODRIM163_DLVRID, odrim163_spec VODRIM163_SPEC, odrim163_sdate VODRIM163_SDATE, ODRIM163_EDATE VODRIM163_EDATE, MAX(odrim163_unit) VODRIM163_UNIT FROM odrim163_itemcost GROUP BY odrim163_itemid, odrim163_dlvrid, odrim163_spec, odrim163_sdate, ODRIM163_EDATE) VODRIM163_ITEMCOST, (SELECT ODRIV910_ITEMID ODRIM910_ITEMID, ODRIV910_SPEC ODRIM910_SPEC, T2.STRID ODRIM910_STRID, ODRIV910_SDATE ODRIM910_SDATE, ODRIV910_EDATE ODRIM910_EDATE, ODRIV910_URTLGRS ODRIM910_URTLGRS, ODRIV910_URTLNET ODRIM910_URTLNET FROM ODRIV910_ORGURTL T1, (SELECT ODRIM080_strid ORGID, ODRIM080_ORGID STRID, 1 LEVE FROM ODRIM080_STORE ODRIM080_STORE11 UNION ALL SELECT ODRIM080_PRREGIONID, ODRIM080_ORGID, 2 FROM ODRIM080_STORE ODRIM080_STORE21 UNION ALL SELECT ODRIM010_COMID, ODRIM080_ORGID, 3 FROM ODRIM080_STORE ODRIM080_STORE31, ODRIM010_COMPANY ODRIM010_COMPANY1, ODRIM031_ACCREGION ODRIM031_ACCREGION1 WHERE ODRIM010_COMID = ODRIM031_COMID AND ODRIM080_ACCREGIONID = ODRIM031_ACCREGIONID) T2 WHERE ODRIV910_ORGID = T2.ORGID AND NOT EXISTS (SELECT 1 FROM ODRIV910_ORGURTL TT1, (SELECT ODRIM080_strid ORGID, ODRIM080_ORGID STRID, 1 LEVE FROM ODRIM080_STORE ODRIM080_STORE12 UNION ALL SELECT ODRIM080_PRREGIONID, ODRIM080_ORGID, 2 FROM ODRIM080_STORE ODRIM080_STORE22 UNION ALL SELECT ODRIM010_COMID, ODRIM080_ORGID, 3 FROM ODRIM080_STORE ODRIM080_STORE32, ODRIM010_COMPANY ODRIM010_COMPANY2, ODRIM031_ACCREGION ODRIM031_ACCREGION2 WHERE ODRIM010_COMID = ODRIM031_COMID || '||''''''||' AND ODRIM080_ACCREGIONID = ODRIM031_ACCREGIONID || '||''''''||') TT2 WHERE ODRIV910_ORGID = TT2.ORGID AND T1.ODRIV910_ITEMID = TT1.ODRIV910_ITEMID AND T1.ODRIV910_SPEC = TT1.ODRIV910_SPEC AND T2.STRID = TT2.STRID AND T2.LEVE > TT2.LEVE)) ODRIM910_STOREURTL, ODRIM210_DELIVERER, ODRIP011_STOCK, ODRIM161_ITEMDLV, ODRD121_RETAPPLYD, ODRIS020_PARA, ODRIM080_STORE, ODRIM150_ITEM, ODRIM013_SV, ODRIM012_DO WHERE ODRD121_RETAPPLYD.ODRD121_ITEMID = ODRIM150_ITEM.ODRIM150_ITEMID AND ODRD121_RETAPPLYD.ODRD121_ORGID = ODRIM080_STORE.ODRIM080_ORGID AND ODRIM910_STOREURTL.ODRIM910_STRID = ODRIM080_STORE.ODRIM080_ORGID AND ODRD121_RETAPPLYD.ODRD121_ITEMID = ODRIM910_STOREURTL.ODRIM910_ITEMID AND ODRD121_RETAPPLYD.ODRD121_SPEC = ODRIM910_STOREURTL.ODRIM910_SPEC AND ODRD121_RETAPPLYD.ODRD121_ITEMID = ODRIM161_ITEMDLV.ODRIM161_ITEMID AND ODRIM210_DELIVERER.ODRIM210_ORGID = ODRIM161_ITEMDLV.ODRIM161_DLVRID AND ODRD121_RETAPPLYD.ODRD121_ITEMID = VODRIM163_ITEMCOST.VODRIM163_ITEMID AND ODRIM210_DELIVERER.ODRIM210_ORGID = VODRIM163_ITEMCOST.VODRIM163_DLVRID AND ODRD121_RETAPPLYD.ODRD121_SPEC = VODRIM163_ITEMCOST.VODRIM163_SPEC AND ODRD121_RETAPPLYD.ODRD121_ITEMID = ODRIP011_STOCK.ODRIP011_ITEMID AND ODRIM210_DELIVERER.ODRIM210_ORGID = ODRIP011_STOCK.ODRIP011_ORGID AND ODRIM080_STORE.ODRIM080_SVID = ODRIM013_SV.ODRIM013_SVID AND ODRIM013_SV.ODRIM013_DOID = ODRIM012_DO.ODRIM012_DOID AND ODRIS020_PARA.ODRIS020_PARACD = ODRD121_RETAPPLYD.ODRD121_RETREASONID AND ODRD121_RETAPPLYD.ODRD121_CHKFLG = 0 AND '||itmid||' = ODRIM150_ITEM.ODRIM150_ITEMID AND ODRIM150_ITEM.ODRIM150_ITEMID = ODRIM910_STOREURTL.ODRIM910_ITEMID AND ODRIM150_ITEM.ODRIM150_ITEMID = ODRIM161_ITEMDLV.ODRIM161_ITEMID AND ODRIM150_ITEM.ODRIM150_ITEMID = VODRIM163_ITEMCOST.VODRIM163_ITEMID AND ODRIM150_ITEM.ODRIM150_ITEMID = ODRIP011_STOCK.ODRIP011_ITEMID AND '||itmid||' = ODRD121_RETAPPLYD.ODRD121_ITEMID AND ODRIM910_STOREURTL.ODRIM910_STRID = ODRD121_RETAPPLYD.ODRD121_ORGID AND ODRIM910_STOREURTL.ODRIM910_ITEMID = ODRIM161_ITEMDLV.ODRIM161_ITEMID AND ODRIM910_STOREURTL.ODRIM910_ITEMID = VODRIM163_ITEMCOST.VODRIM163_ITEMID AND ODRIM910_STOREURTL.ODRIM910_ITEMID = ODRIP011_STOCK.ODRIP011_ITEMID'; --记录当前记录 timidcount:=timidcount+1; END IF; COMMIT; END LOOP; CLOSE GetStrView; --如果当前记录大于0则采用刷新物化视图及情况临时表数据,否不进行该操作 IF timidcount>0 THEN --使视图得到最新刷新的数据 DBMS_MVIEW.REFRESH('ODRD121_RETAPPLYD_REPORTS_VIEW','C'); --清楚临时表数据 EXECUTE IMMEDIATE 'TRUNCATE TABLE ODRD121_RETAPPLYD_REPORT'; END IF; EXCEPTION WHEN OTHERS THEN dbms_output.put_line('查询、插入数据时产生异常!'); END ODRD121_RETAPPLYD_REPORTS; / --物化视图创建ODRD121_RETAPPLYD_REPORTS_VIEW创建 CREATE MATERIALIZED VIEW ODRD121_RETAPPLYD_REPORTS_VIEW REFRESH FORCE ON DEMAND WITH ROWID AS SELECT "ODRD121_RETAPPLYD_REPORT"."ODRD121_ODRWAY_1" "ODRD121_ODRWAY_1","ODRD121_RETAPPLYD_REPORT"."ODRD121_ORGID_2" "ODRD121_ORGID_2","ODRD121_RETAPPLYD_REPORT"."ODRD121_ODRDATE_3" "ODRD121_ODRDATE_3","ODRD121_RETAPPLYD_REPORT"."ODRD121_STFID_4" "ODRD121_STFID_4","ODRD121_RETAPPLYD_REPORT"."ODRD121_ORDERNO_5" "ODRD121_ORDERNO_5","ODRD121_RETAPPLYD_REPORT"."ODRD121_LINENO_6" "ODRD121_LINENO_6","ODRD121_RETAPPLYD_REPORT"."ODRD121_ITEMID_7" "ODRD121_ITEMID_7","ODRD121_RETAPPLYD_REPORT"."ODRD121_PLUCD_8" "ODRD121_PLUCD_8","ODRD121_RETAPPLYD_REPORT"."ODRD121_SPEC_9" "ODRD121_SPEC_9","ODRD121_RETAPPLYD_REPORT"."ODRD121_TRIP_10" "ODRD121_TRIP_10","ODRD121_RETAPPLYD_REPORT"."ODRD121_PACKQTY_11" "ODRD121_PACKQTY_11","ODRD121_RETAPPLYD_REPORT"."ODRD121_UNITQTY_12" "ODRD121_UNITQTY_12","ODRD121_RETAPPLYD_REPORT"."ODRD121_ENTDATE_13" "ODRD121_ENTDATE_13","ODRD121_RETAPPLYD_REPORT"."ODRD121_RETREASONID_14" "ODRD121_RETREASONID_14","ODRD121_RETAPPLYD_REPORT"."ODRD121_GENDATE_15" "ODRD121_GENDATE_15","ODRD121_RETAPPLYD_REPORT"."ODRD121_HQPACKQTY_16" "ODRD121_HQPACKQTY_16","ODRD121_RETAPPLYD_REPORT"."ODRD121_HQUNITQTY_17" "ODRD121_HQUNITQTY_17","ODRD121_RETAPPLYD_REPORT"."ODRD121_CHKFLG_18" "ODRD121_CHKFLG_18","ODRD121_RETAPPLYD_REPORT"."ODRD121_CHKSTFID_19" "ODRD121_CHKSTFID_19","ODRD121_RETAPPLYD_REPORT"."ODRD121_CHKDATE_20" "ODRD121_CHKDATE_20","ODRD121_RETAPPLYD_REPORT"."ODRD121_SNDFLG_21" "ODRD121_SNDFLG_21","ODRD121_RETAPPLYD_REPORT"."ODRD121_SNDDATE_22" "ODRD121_SNDDATE_22","ODRD121_RETAPPLYD_REPORT"."ODRD121_HEADFLG_23" "ODRD121_HEADFLG_23","ODRD121_RETAPPLYD_REPORT"."ODRIM150_ITEMID_24" "ODRIM150_ITEMID_24","ODRD121_RETAPPLYD_REPORT"."ODRIM150_PLUCD_25" "ODRIM150_PLUCD_25","ODRD121_RETAPPLYD_REPORT"."ODRIM150_ITEMCNM_26" "ODRIM150_ITEMCNM_26","ODRD121_RETAPPLYD_REPORT"."VODRIM163_ITEMID_27" "VODRIM163_ITEMID_27","ODRD121_RETAPPLYD_REPORT"."VODRIM163_DLVRID_28" "VODRIM163_DLVRID_28","ODRD121_RETAPPLYD_REPORT"."VODRIM163_SPEC_29" "VODRIM163_SPEC_29","ODRD121_RETAPPLYD_REPORT"."VODRIM163_SDATE_30" "VODRIM163_SDATE_30","ODRD121_RETAPPLYD_REPORT"."VODRIM163_UNIT_31" "VODRIM163_UNIT_31","ODRD121_RETAPPLYD_REPORT"."ODRIM910_URTLGRS_32" "ODRIM910_URTLGRS_32","ODRD121_RETAPPLYD_REPORT"."ODRIM910_URTLNET_33" "ODRIM910_URTLNET_33","ODRD121_RETAPPLYD_REPORT"."ODRIP011_ITEMID_34" "ODRIP011_ITEMID_34","ODRD121_RETAPPLYD_REPORT"."ODRIP011_ORGID_35" "ODRIP011_ORGID_35","ODRD121_RETAPPLYD_REPORT"."ODRIP011_QTY_36" "ODRIP011_QTY_36","ODRD121_RETAPPLYD_REPORT"."ODRIM210_DLVRID_37" "ODRIM210_DLVRID_37","ODRD121_RETAPPLYD_REPORT"."ODRIM210_DLVRCD_38" "ODRIM210_DLVRCD_38","ODRD121_RETAPPLYD_REPORT"."ODRIM210_DLVRCNM_39" "ODRIM210_DLVRCNM_39","ODRD121_RETAPPLYD_REPORT"."ODRIM080_STRID_40" "ODRIM080_STRID_40","ODRD121_RETAPPLYD_REPORT"."ODRIM080_STRCD_41" "ODRIM080_STRCD_41","ODRD121_RETAPPLYD_REPORT"."ODRIM080_SVID_42" "ODRIM080_SVID_42","ODRD121_RETAPPLYD_REPORT"."ODRIM080_ORGID_43" "ODRIM080_ORGID_43","ODRD121_RETAPPLYD_REPORT"."ODRIM080_STRCNM_44" "ODRIM080_STRCNM_44","ODRD121_RETAPPLYD_REPORT"."ODRIM013_SVID_45" "ODRIM013_SVID_45","ODRD121_RETAPPLYD_REPORT"."ODRIM013_SVCD_46" "ODRIM013_SVCD_46","ODRD121_RETAPPLYD_REPORT"."ODRIM013_DOID_47" "ODRIM013_DOID_47","ODRD121_RETAPPLYD_REPORT"."ODRIM012_DOID_48" "ODRIM012_DOID_48","ODRD121_RETAPPLYD_REPORT"."ODRIM012_DOCD_49" "ODRIM012_DOCD_49","ODRD121_RETAPPLYD_REPORT"."ODRIM161_ITEMID_50" "ODRIM161_ITEMID_50","ODRD121_RETAPPLYD_REPORT"."ODRIM161_DLVRID_51" "ODRIM161_DLVRID_51","ODRD121_RETAPPLYD_REPORT"."ODRIS020_PARACD_52" "ODRIS020_PARACD_52","ODRD121_RETAPPLYD_REPORT"."ODRIS020_PARAVALUE_53" "ODRIS020_PARAVALUE_53" FROM "ODRD121_RETAPPLYD_REPORT" "ODRD121_RETAPPLYD_REPORT"; |