|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
为提升BOM解析查询的效率建立BOM物化视图;脚本如下:
- create materialized view MVIEW_BOM_EXPAND
- refresh complete on demand
- start with to_date('21-10-2022 22:00:00', 'dd-mm-yyyy hh24:mi:ss') next to_date( concat( to_char( sysdate+1,'dd-mm-yyyy'),' 22:00:00'),'dd-mm-yyyy hh24:mi:ss') /** 创建BOM展开的物化视图MVIEW_BOM_EXPAND,每天晚上10点刷新 */
- as
- select
- bom.cbomid
- ,bom.vbillcode
- ,bom.hversion
- ,bom.pk_org
- ,bom.hcmaterialvid
- ,bom.hnparentnum
- ,bom.hcmeasureid
- ,bom.hnassparentnum
- ,bom.hcassmeasureid
- ,bomb.cbom_bid
- ,bomb.cmaterialvid
- ,bomb.nitemnum / bomb.ibasenum as cnum
- ,bomb.cmeasureid
- ,bomb.nassitemnum /bomb.ibasenum as cassnum
- ,bomb.cassmeasureid
- from bd_bom bom
- inner join bd_bom_b bomb on bomb.cbomid= bom.cbomid
- where bom.dr=0
- and bom.fbillstatus = 1 /*-1=自由,0=审批不通过,1=审批通过,2=审批中*/
- and bom.fbomtype = 1 /*1=生产BOM,2=包装BOM,3=配置BOM*/
- and bom.hfversiontype =1 /*1=有效版本,2=无效版本*/
- UNION ALL
- /*第2层BOM*/
- select
- bom.cbomid
- ,bom.vbillcode
- ,bom.hversion
- ,bom.pk_org
- ,bom.hcmaterialvid
- ,bom.hnparentnum
- ,bom.hcmeasureid
- ,bom.hnassparentnum
- ,bom.hcassmeasureid
- ,bomb1.cbom_bid
- ,bomb1.cmaterialvid
- ,(bomb.nitemnum / bomb.ibasenum) * ((bomb1.nitemnum / bomb1.ibasenum) / bom1.hnparentnum) as cnum
- ,bomb1.cmeasureid
- ,(bomb.nassitemnum /bomb.ibasenum) * ((bomb1.nassitemnum /bomb1.ibasenum) / bom1.hnassparentnum) as cassnum
- ,bomb1.cassmeasureid
- from bd_bom bom
- inner join bd_bom_b bomb on bomb.cbomid= bom.cbomid
- inner join bd_bom bom1 on bomb.cmaterialvid = bom1.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom1.hcmeasureid = bomb.cmeasureid
- and bom1.hcassmeasureid = bomb.cassmeasureid
- and bom1.dr=0
- and bom1.fbillstatus = bom.fbillstatus
- and bom1.fbomtype = bom.fbomtype
- and bom1.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom1.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb1 on bomb1.cbomid = bom1.cbomid
- where bom.dr=0
- and bom.fbillstatus = 1 /*-1=自由,0=审批不通过,1=审批通过,2=审批中*/
- and bom.fbomtype = 1 /*1=生产BOM,2=包装BOM,3=配置BOM*/
- and bom.hfversiontype =1 /*1=有效版本,2=无效版本*/
- UNION ALL
- /*第3层BOM*/
- select
- bom.cbomid
- ,bom.vbillcode
- ,bom.hversion
- ,bom.pk_org
- ,bom.hcmaterialvid
- ,bom.hnparentnum
- ,bom.hcmeasureid
- ,bom.hnassparentnum
- ,bom.hcassmeasureid
- ,bomb2.cbom_bid
- ,bomb2.cmaterialvid
- ,(bomb.nitemnum / bomb.ibasenum) * ((bomb1.nitemnum / bomb1.ibasenum) / bom1.hnparentnum) * ((bomb2.nitemnum / bomb2.ibasenum) / bom2.hnparentnum) as cnum
- ,bomb2.cmeasureid
- ,(bomb.nassitemnum /bomb.ibasenum) * ((bomb1.nassitemnum /bomb1.ibasenum) / bom1.hnassparentnum) * ((bomb2.nassitemnum /bomb2.ibasenum) / bom2.hnassparentnum) as cassnum
- ,bomb2.cassmeasureid
- from bd_bom bom
- inner join bd_bom_b bomb on bomb.cbomid= bom.cbomid
- inner join bd_bom bom1 on bomb.cmaterialvid = bom1.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom1.hcmeasureid = bomb.cmeasureid
- and bom1.hcassmeasureid = bomb.cassmeasureid
- and bom1.dr=0
- and bom1.fbillstatus = bom.fbillstatus
- and bom1.fbomtype = bom.fbomtype
- and bom1.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom1.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb1 on bomb1.cbomid = bom1.cbomid
- inner join bd_bom bom2 on bomb1.cmaterialvid = bom2.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom2.hcmeasureid = bomb1.cmeasureid
- and bom2.hcassmeasureid = bomb1.cassmeasureid
- and bom2.dr=0
- and bom2.fbillstatus = bom.fbillstatus
- and bom2.fbomtype = bom.fbomtype
- and bom2.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom2.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb2 on bomb2.cbomid = bom2.cbomid
- where bom.dr=0
- and bom.fbillstatus = 1 /*-1=自由,0=审批不通过,1=审批通过,2=审批中*/
- and bom.fbomtype = 1 /*1=生产BOM,2=包装BOM,3=配置BOM*/
- and bom.hfversiontype =1 /*1=有效版本,2=无效版本*/
- UNION ALL
- /*第4层BOM*/
- select
- bom.cbomid
- ,bom.vbillcode
- ,bom.hversion
- ,bom.pk_org
- ,bom.hcmaterialvid
- ,bom.hnparentnum
- ,bom.hcmeasureid
- ,bom.hnassparentnum
- ,bom.hcassmeasureid
- ,bomb3.cbom_bid
- ,bomb3.cmaterialvid
- ,(bomb.nitemnum / bomb.ibasenum) * ((bomb1.nitemnum / bomb1.ibasenum) / bom1.hnparentnum) * ((bomb2.nitemnum / bomb2.ibasenum) / bom2.hnparentnum) * ((bomb3.nitemnum / bomb3.ibasenum) / bom3.hnparentnum) as cnum
- ,bomb3.cmeasureid
- ,(bomb.nassitemnum /bomb.ibasenum) * ((bomb1.nassitemnum /bomb1.ibasenum) / bom1.hnassparentnum) * ((bomb2.nassitemnum /bomb2.ibasenum) / bom2.hnassparentnum) * ((bomb3.nassitemnum /bomb3.ibasenum) / bom3.hnassparentnum) as cassnum
- ,bomb3.cassmeasureid
- from bd_bom bom
- inner join bd_bom_b bomb on bomb.cbomid= bom.cbomid
- inner join bd_bom bom1 on bomb.cmaterialvid = bom1.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom1.hcmeasureid = bomb.cmeasureid
- and bom1.hcassmeasureid = bomb.cassmeasureid
- and bom1.dr=0
- and bom1.fbillstatus = bom.fbillstatus
- and bom1.fbomtype = bom.fbomtype
- and bom1.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom1.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb1 on bomb1.cbomid = bom1.cbomid
- inner join bd_bom bom2 on bomb1.cmaterialvid = bom2.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom2.hcmeasureid = bomb1.cmeasureid
- and bom2.hcassmeasureid = bomb1.cassmeasureid
- and bom2.dr=0
- and bom2.fbillstatus = bom.fbillstatus
- and bom2.fbomtype = bom.fbomtype
- and bom2.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom2.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb2 on bomb2.cbomid = bom2.cbomid
- inner join bd_bom bom3 on bomb2.cmaterialvid = bom3.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom3.hcmeasureid = bomb2.cmeasureid
- and bom3.hcassmeasureid = bomb2.cassmeasureid
- and bom3.dr=0
- and bom3.fbillstatus = bom.fbillstatus
- and bom3.fbomtype = bom.fbomtype
- and bom3.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom3.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb3 on bomb3.cbomid = bom3.cbomid
- where bom.dr=0
- and bom.fbillstatus = 1 /*-1=自由,0=审批不通过,1=审批通过,2=审批中*/
- and bom.fbomtype = 1 /*1=生产BOM,2=包装BOM,3=配置BOM*/
- and bom.hfversiontype =1 /*1=有效版本,2=无效版本*/
- UNION ALL
- /*第5层BOM*/
- select
- bom.cbomid
- ,bom.vbillcode
- ,bom.hversion
- ,bom.pk_org
- ,bom.hcmaterialvid
- ,bom.hnparentnum
- ,bom.hcmeasureid
- ,bom.hnassparentnum
- ,bom.hcassmeasureid
- ,bomb4.cbom_bid
- ,bomb4.cmaterialvid
- ,(bomb.nitemnum / bomb.ibasenum) * ((bomb1.nitemnum / bomb1.ibasenum) / bom1.hnparentnum) * ((bomb2.nitemnum / bomb2.ibasenum) / bom2.hnparentnum) * ((bomb3.nitemnum / bomb3.ibasenum) / bom3.hnparentnum) * ((bomb4.nitemnum / bomb4.ibasenum) / bom4.hnparentnum) as cnum
- ,bomb4.cmeasureid
- ,(bomb.nassitemnum /bomb.ibasenum) * ((bomb1.nassitemnum /bomb1.ibasenum) / bom1.hnassparentnum) * ((bomb2.nassitemnum /bomb2.ibasenum) / bom2.hnassparentnum) * ((bomb3.nassitemnum /bomb3.ibasenum) / bom3.hnassparentnum) * ((bomb4.nassitemnum /bomb4.ibasenum) / bom4.hnassparentnum) as cassnum
- ,bomb4.cassmeasureid
- from bd_bom bom
- inner join bd_bom_b bomb on bomb.cbomid= bom.cbomid
- inner join bd_bom bom1 on bomb.cmaterialvid = bom1.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom1.hcmeasureid = bomb.cmeasureid
- and bom1.hcassmeasureid = bomb.cassmeasureid
- and bom1.dr=0
- and bom1.fbillstatus = bom.fbillstatus
- and bom1.fbomtype = bom.fbomtype
- and bom1.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom1.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb1 on bomb1.cbomid = bom1.cbomid
- inner join bd_bom bom2 on bomb1.cmaterialvid = bom2.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom2.hcmeasureid = bomb1.cmeasureid
- and bom2.hcassmeasureid = bomb1.cassmeasureid
- and bom2.dr=0
- and bom2.fbillstatus = bom.fbillstatus
- and bom2.fbomtype = bom.fbomtype
- and bom2.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom2.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb2 on bomb2.cbomid = bom2.cbomid
- inner join bd_bom bom3 on bomb2.cmaterialvid = bom3.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom3.hcmeasureid = bomb2.cmeasureid
- and bom3.hcassmeasureid = bomb2.cassmeasureid
- and bom3.dr=0
- and bom3.fbillstatus = bom.fbillstatus
- and bom3.fbomtype = bom.fbomtype
- and bom3.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom3.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb3 on bomb3.cbomid = bom3.cbomid
- inner join bd_bom bom4 on bomb3.cmaterialvid = bom4.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom4.hcmeasureid = bomb3.cmeasureid
- and bom4.hcassmeasureid = bomb3.cassmeasureid
- and bom4.dr=0
- and bom4.fbillstatus = bom.fbillstatus
- and bom4.fbomtype = bom.fbomtype
- and bom4.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom4.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb4 on bomb4.cbomid = bom4.cbomid
- where bom.dr=0
- and bom.fbillstatus = 1 /*-1=自由,0=审批不通过,1=审批通过,2=审批中*/
- and bom.fbomtype = 1 /*1=生产BOM,2=包装BOM,3=配置BOM*/
- and bom.hfversiontype =1 /*1=有效版本,2=无效版本*/
- UNION ALL
- /*第6层BOM*/
- select
- bom.cbomid
- ,bom.vbillcode
- ,bom.hversion
- ,bom.pk_org
- ,bom.hcmaterialvid
- ,bom.hnparentnum
- ,bom.hcmeasureid
- ,bom.hnassparentnum
- ,bom.hcassmeasureid
- ,bomb5.cbom_bid
- ,bomb5.cmaterialvid
- ,(bomb.nitemnum / bomb.ibasenum) * ((bomb1.nitemnum / bomb1.ibasenum) / bom1.hnparentnum) * ((bomb2.nitemnum / bomb2.ibasenum) / bom2.hnparentnum) * ((bomb3.nitemnum / bomb3.ibasenum) / bom3.hnparentnum) * ((bomb4.nitemnum / bomb4.ibasenum) / bom4.hnparentnum) * ((bomb5.nitemnum / bomb5.ibasenum) / bom5.hnparentnum) as cnum
- ,bomb5.cmeasureid
- ,(bomb.nassitemnum /bomb.ibasenum) * ((bomb1.nassitemnum /bomb1.ibasenum) / bom1.hnassparentnum) * ((bomb2.nassitemnum /bomb2.ibasenum) / bom2.hnassparentnum) * ((bomb3.nassitemnum /bomb3.ibasenum) / bom3.hnassparentnum) * ((bomb4.nassitemnum /bomb4.ibasenum) / bom4.hnassparentnum) * ((bomb5.nassitemnum /bomb5.ibasenum) / bom5.hnassparentnum) as cassnum
- ,bomb5.cassmeasureid
- from bd_bom bom
- inner join bd_bom_b bomb on bomb.cbomid= bom.cbomid
- inner join bd_bom bom1 on bomb.cmaterialvid = bom1.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom1.hcmeasureid = bomb.cmeasureid
- and bom1.hcassmeasureid = bomb.cassmeasureid
- and bom1.dr=0
- and bom1.fbillstatus = bom.fbillstatus
- and bom1.fbomtype = bom.fbomtype
- and bom1.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom1.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb1 on bomb1.cbomid = bom1.cbomid
- inner join bd_bom bom2 on bomb1.cmaterialvid = bom2.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom2.hcmeasureid = bomb1.cmeasureid
- and bom2.hcassmeasureid = bomb1.cassmeasureid
- and bom2.dr=0
- and bom2.fbillstatus = bom.fbillstatus
- and bom2.fbomtype = bom.fbomtype
- and bom2.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom2.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb2 on bomb2.cbomid = bom2.cbomid
- inner join bd_bom bom3 on bomb2.cmaterialvid = bom3.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom3.hcmeasureid = bomb2.cmeasureid
- and bom3.hcassmeasureid = bomb2.cassmeasureid
- and bom3.dr=0
- and bom3.fbillstatus = bom.fbillstatus
- and bom3.fbomtype = bom.fbomtype
- and bom3.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom3.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb3 on bomb3.cbomid = bom3.cbomid
- inner join bd_bom bom4 on bomb3.cmaterialvid = bom4.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom4.hcmeasureid = bomb3.cmeasureid
- and bom4.hcassmeasureid = bomb3.cassmeasureid
- and bom4.dr=0
- and bom4.fbillstatus = bom.fbillstatus
- and bom4.fbomtype = bom.fbomtype
- and bom4.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom4.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb4 on bomb4.cbomid = bom4.cbomid
- inner join bd_bom bom5 on bomb4.cmaterialvid = bom5.hcmaterialvid /*物料相等,且计量单位相同的默认BOM*/
- and bom5.hcmeasureid = bomb4.cmeasureid
- and bom5.hcassmeasureid = bomb4.cassmeasureid
- and bom5.dr=0
- and bom5.fbillstatus = bom.fbillstatus
- and bom5.fbomtype = bom.fbomtype
- and bom5.hfversiontype = 1 /*1=有效版本,2=无效版本*/
- and bom5.hbdefault ='Y' /*取默认BOM*/
- inner join bd_bom_b bomb5 on bomb5.cbomid = bom5.cbomid
- where bom.dr=0
- and bom.fbillstatus = 1 /*-1=自由,0=审批不通过,1=审批通过,2=审批中*/
- and bom.fbomtype = 1 /*1=生产BOM,2=包装BOM,3=配置BOM*/
- and bom.hfversiontype =1 /*1=有效版本,2=无效版本*/
- UNION ALL
复制代码
|
|