这个是原本的sql,用了很多方法,DBMS_LOB.SUBSTR,COALESCE都试了,还是没有效果
with mps_info as (
select distinct nvl(a.productfamily, b.productfamily) productfamily,
nvl(a.timename, b.mfgmonth) mfgmonth, nvl( b.mps_modify , a.STRETCHTARGET) mps_modify
from (
select prodtype||'-'||category productfamily, timename , STRETCHTARGET
from P_MFG_CREATE.rpt_tgv_kpi_spec
where kpiname ='InPut'
and timetype = 'M'
and kpitype ='Prod'
and fabsite ='Overall'
and timename ='2025-M09'
) a full join (select * from P_MFG_CREATE.RPT_TGT_RAP_MPSINPUT_CONFIG where 1=1
and mfgmonth ='2025-M09'
) b
on a.productfamily = b.productfamily
and a.timename = b.mfgmonth
),
basic_info as (
select groupname , recipe_group , recipe , productfamily , requiredcapability capability,
p_mfg_create.fun_LISTAGGPURE(listagg(stagename ,',') within group(order by stagename)) as stagename ,
avG(tgtuptime) tgtuptime , avg(tgtme) tgtme , avg(wph) wph , SUM(STEP_CNT) STEP_CNT
from ( select distinct groupname ,recipe_group , recipe , productfamily , requiredcapability ,
stagename ,tgtuptime ,tgtme ,wph , STEP_CNT
from p_MFG_create.RPT_ODST_PRDRAP_STATICSTATE
where 1=1
and productname in ('Y006C','Y013D','Y046D','Y047C','Y047D','Y065B','Y065C','Y067A','Y068C','Y070C','Y085B','Y087F','Y088F','Y095B','Y095D','Y096B','Y096C','Y096D','Y097F','Y097G','Y098C','Y098D','Y125B','Y126B','Y127D','Y127E','Y128A','Y128B','Y128C','Y130C','Y148A','Y175B','Y176C','Y177A','Y177B','Y178B','Y178C','Y186E','Y188A','Y188B','Y188D','Y188F','Y195B','Y196C','Y196E','Y196G','Y197B','Y198C','Y198D','Y198F','Y198G','Y198H','Y800HM01') and groupname in ('BE TEOS') and groupname !='OTHER') a
group by groupname ,recipe_group , recipe , productfamily , requiredcapability
),
non_key_eqp as (
select eqpid
from P_MFG_CREATE.RPT_TGT_GROUP_EQP e join P_MFG_CREATE.RPT_TGT_GROUP_RULE g
on e.group_key = g.group_key
where 1=1 and e.enable='Y' AND e.FLAG='Y' and e.category='Special'
and instr(e.eqpid,'_')>0
and g.group_name not in ('BE TEOS')
),
tmp_eqp_list as (
select distinct a.eqpid , b.full_config
from (
select eqpid
from P_MFG_CREATE.RPT_TGT_GROUP_EQP e join P_MFG_CREATE.RPT_TGT_GROUP_RULE g
on e.group_key = g.group_key
where 1=1 and e.enable='Y'
AND e.FLAG='Y'
and group_name in ('BE TEOS') union
select eqpid
from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG
where category ='eqpid'
and mfgmonth ='2025-M09'
and eqpgroup in ('BE TEOS')
union
select eqpid
from p_MFG_create.RPT_ODST_PRDRAP_PPID_CHK
where recipelist in (select recipe from basic_info)
) a left join (
select DISTINCT eqpid,PROCUNITCOUNT/decode(TAKTTIMESTARTCHAMBERLIKE,0,'',TAKTTIMESTARTCHAMBERLIKE) full_config
from P_MFG_CREATE.RPT_TGT_WPH_EQP_CONFIG
WHERE EQPID !='Dummy'
) b
on substr(a.eqpid,1,instr(a.eqpid,'_')-1) = b.eqpid
),
--剔除non key chamber
eqp_list as (
select t.*
from tmp_eqp_list t left join non_key_eqp n
on t.eqpid = n.eqpid
where n.eqpid is null
),
eqp_flag as (
select *
from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG
where category ='eqpid'
and mfgmonth ='2025-M09'
and eqpgroup in ('BE TEOS') ),
--每个机台的ppid状态、填写的plan release状态
temp_chm_state_info as (
select distinct b.groupname , b.recipe_group , b.recipe , b.productfamily , e.eqpid , nvl(p.is_ppid_enable,'0') is_ppid_enable, nvl(f.note ,'0') note ,
nvl( e.full_config ,'0') full_config
from basic_info b left join eqp_list e
on 1=1
left join ( select recipelist ,eqpid, is_ppid_enable from p_MFG_create.RPT_ODST_PRDRAP_PPID_CHK where 1=1 and recipelist in (select recipe from basic_info)
group by recipelist ,eqpid,is_ppid_enable ) p
on b.recipe = p.recipelist and e.eqpid = p.eqpid left join eqp_flag f
on b.groupname = f.eqpgroup
--and b.recipe_group = f.recipegroup
and b.recipe = f.recipename
and b.productfamily = f.productfamily
and e.eqpid = f.eqpid left join P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r
on r.category ='if recipe active'
and b.groupname = r.eqpgroup
--and b.recipe_group = r.recipegroup
and b.recipe = r.recipename
and b.productfamily = r.productfamily
where nvl(r.note,'Y') ='Y'
),
--chamber plan rls count 和 act rls count
chm_state_info as (
select groupname , recipe_group , recipe , productfamily , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls
from temp_chm_state_info
group by groupname , recipe_group , recipe , productfamily
),
--整机count
eqp_state_info as (
select groupname , recipe_group , recipe , productfamily ,
sum(case when a.Plan_total_cnt = c.total_cnt then 1 else 0 end ) Plan_total_cnt ,
sum(case when a.act_total_cnt = c.total_cnt then 1 else 0 end ) act_total_cnt , max(full_config) full_config
from (
select groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1) eqpid, max(full_config) full_config ,
sum(note) Plan_total_cnt , sum(is_ppid_enable) act_total_cnt
from temp_chm_state_info
where eqpid like '%/_%' escape '/'
group by groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1)
) a join (select substr(eqpid,1 ,7 ) eqpid , count(1) total_cnt from CENTERDB.RPT_BRT_EQP_LST where CONSTRUCTTYPE ='Chamber' group by substr(eqpid,1 ,7 )) c
on a.eqpid = c.eqpid
group by groupname , recipe_group , recipe , productfamily
),
temp_detail_info as (
select s.groupname, s.recipe_group, s.recipe, s.productfamily, s.capability, s.stagename, nvl(r.note,'Y') if_recipe_active ,nvl(r1.note,'1') MPS_Ratio ,
s.tgtuptime , s.tgtme , s.wph , s.tgtuptime*s.tgtme*s.wph*720 k_unit , null admin_flag , null dedicate_tool_count , null dedicate_ratio ,
c.plan_rls,
case when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) ) >=1
then c.plan_rls / ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) )
when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) ) <1
then c.plan_rls / 1
end plan_path ,
case when floor(c.plan_rls/e.full_config) !=0 then e.Plan_total_cnt/floor(c.plan_rls/e.full_config) end Plan_total_ratio,
c.ACT_rls ,
case when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) )>=1
then c.ACT_rls / ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) )
when s.step_cnt*m.mps_modify*nvl(r1.note,'1') !=0 and ( ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) )<1
then c.ACT_rls / 1
end act_path ,
case when floor(c.ACT_rls/e.full_config) !=0 then e.act_total_cnt/floor(c.ACT_rls/e.full_config) end act_total_ratio ,
s.step_cnt*to_number(m.mps_modify) mps_modify , 4 rank ,
case when s.tgtuptime*s.tgtme*s.wph*720 !=0 then ( s.step_cnt*m.mps_modify*nvl(r1.note,'1') ) / (s.tgtuptime*s.tgtme*s.wph*720) end demand ,
nvl(e.act_total_cnt,'0') act_total_cnt, nvl(e.Plan_total_cnt,'0') Plan_total_cnt
from basic_info s
LEFT JOIN P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r
on r.category ='if recipe active'
and s.groupname = r.eqpgroup
--and s.recipe_group = r.recipegroup
and s.recipe = r.recipename
and s.productfamily = r.productfamily LEFT JOIN P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r1
ON r1.category ='MPS Ratio'
and r1.mfgmonth ='2025-M09'
and s.groupname = r1.eqpgroup
--and s.recipe_group = r1.recipegroup
and s.recipe = r1.recipename
and s.productfamily = r1.productfamily
left join mps_info m
on s.productfamily = m.productfamily left join chm_state_info c
on s.groupname = c.groupname
and s.recipe_group = c.recipe_group
and s.recipe = c.recipe
and s.productfamily = c.productfamily left join eqp_state_info e
on s.groupname = e.groupname
and s.recipe_group = e.recipe_group
and s.recipe = e.recipe
and s.productfamily = e.productfamily
),
detail_info as (
select groupname, recipe_group, recipe, productfamily, capability, stagename, if_recipe_active , MPS_Ratio ,
tgtuptime , tgtme , wph , k_unit , admin_flag , dedicate_tool_count , dedicate_ratio ,
case when if_recipe_active='Y' then plan_rls end plan_rls,
case when if_recipe_active='Y' then plan_path end plan_path,
case when if_recipe_active='Y' then Plan_total_ratio end Plan_total_ratio,
case when if_recipe_active='Y' then ACT_rls end ACT_rls,
case when if_recipe_active='Y' then act_path end act_path,
case when if_recipe_active='Y' then act_total_ratio end act_total_ratio,
case when if_recipe_active='Y' then mps_modify end mps_modify, 4 rank ,
case when if_recipe_active='Y' then demand end demand,
case when if_recipe_active='Y' then act_total_cnt end act_total_cnt,
case when if_recipe_active='Y' then Plan_total_cnt end Plan_total_cnt
from temp_detail_info
),
chm_state_info_recipe as (
select groupname , recipe_group , recipe , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls
from (
select groupname , recipe_group , recipe , eqpid , nvl(max(is_ppid_enable),'0') is_ppid_enable, nvl( max(note) ,'0') note
from temp_chm_state_info
group by groupname , recipe_group , recipe , eqpid
)
group by groupname , recipe_group , recipe
),
--by recipe整机count,直接用by recipe整机数/demand整机数,不要by prod计算再加权
eqp_state_info_recipe as (
select groupname , recipe_group , recipe , count(distinct Plan_total_eqpid ) Plan_total_cnt , count(distinct act_total_eqpid ) act_total_cnt , max(full_config) full_config
from (
select groupname , recipe_group , recipe , productfamily , case when a.Plan_total_cnt = c.total_cnt then a.eqpid end Plan_total_eqpid ,
case when a.act_total_cnt = c.total_cnt then a.eqpid end act_total_eqpid , full_config
from (
select groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1) eqpid, max(full_config) full_config ,
sum(note) Plan_total_cnt , sum(is_ppid_enable) act_total_cnt
from temp_chm_state_info
where eqpid like '%/_%' escape '/'
group by groupname , recipe_group , recipe , productfamily , substr( eqpid ,1,instr(eqpid,'_')-1)
) a join (select substr(eqpid,1 ,7 ) eqpid , count(1) total_cnt from CENTERDB.RPT_BRT_EQP_LST where CONSTRUCTTYPE ='Chamber' group by substr(eqpid,1 ,7 )) c
on a.eqpid = c.eqpid
)
group by groupname , recipe_group , recipe
),
recipe_detail_info as (
select a.groupname , a.recipe_group , a.recipe , a.productfamily ,a.capability , a.stagename , a.if_recipe_active , a.MPS_Ratio , a.tgtuptime , a.tgtme , a.wph , a.k_unit ,
a.admin_flag , a.dedicate_tool_count , a.dedicate_ratio , c.plan_rls ,
case when demand >=1 then c.plan_rls / demand when demand <1 and demand>0 then c.plan_rls / 1 end plan_path ,
case when floor(c.plan_rls/r.full_config) !=0 then r.Plan_total_cnt/floor(c.plan_rls/r.full_config) end Plan_total_ratio ,
c.ACT_rls , case when demand >=1 then c.ACT_rls / demand when demand <1 and demand>0 then c.ACT_rls / 1 end act_path ,
case when floor(c.ACT_rls/r.full_config) !=0 then r.act_total_cnt/floor(c.ACT_rls/r.full_config) end act_total_ratio ,
a.mps_modify , a.rank
from (
select groupname , recipe_group , recipe ,
rtrim(regexp_replace(xmlagg(XMLparse(content productfamily||',' )order by productfamily ).getclobval(),'([^,]+)(,\1)+','\1'),',') productfamily ,
capability ,
rtrim(regexp_replace(xmlagg(XMLparse(content to_char(stagename)||',' )order by to_char(stagename) ).getclobval(),'([^,]+)(,\1)+','\1'),',') stagename ,
null if_recipe_active , null MPS_Ratio , avg(tgtuptime) tgtuptime , avg(tgtme) tgtme , null wph , null k_unit , null admin_flag , null dedicate_tool_count , null dedicate_ratio ,
--case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path ,
--case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio ,
--case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path ,
--case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio ,
sum(demand) demand , sum(mps_modify) mps_modify , 3 rank
from detail_info
GROUP BY groupname , recipe_group , recipe , capability
) a left join chm_state_info_recipe c
on a.groupname = c.groupname and a.recipe_group = c.recipe_group and a.recipe =c.recipe
left join eqp_state_info_recipe r
on a.groupname = r.groupname and a.recipe_group = r.recipe_group and a.recipe =r.recipe
),
chm_state_info_recipegrp as (
select groupname , recipe_group , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls
from (
select groupname , recipe_group , eqpid , nvl(max(is_ppid_enable),'0') is_ppid_enable, nvl( max(note) ,'0') note
from temp_chm_state_info
group by groupname , recipe_group , eqpid
)
group by groupname , recipe_group
),
temp_dedicate_info as (
select distinct eqpgroup , eqpid , recipename
from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG
where category ='eqpid'
and note ='1'
and mfgmonth ='2025-M09'
and EQPGROUP||RECIPENAME||PRODUCTFAMILY NOT IN
(
select EQPGROUP||RECIPENAME||PRODUCTFAMILY
from P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r
where r.category ='if recipe active'
and note ='N'
)
) ,
dedicate_info as (
select recipegroup , eqpgroup, count(distinct eqpid ) dedicate_tool_count
from (
select distinct eqpgroup , eqpid , recipename , recipegroup , count(distinct recipegroup ) over(partition by eqpid ) cnt
from (
select distinct t.eqpgroup , t.eqpid , t.recipename , nvl(s.recipe_group , t.recipename ) recipegroup
from temp_dedicate_info t join p_MFG_create.RPT_ODST_PRDRAP_STATICSTATE s
on t.eqpgroup = s.groupname
and t.recipename = s.recipe
)
)
where cnt =1
group by recipegroup , eqpgroup
) ,
--by recipe group的plan/act整机ratio:用recipename整机ratio结果按MPS加权平均
recipegrp_total_ratio as (
select groupname , recipe_group ,capability ,
case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio ,
case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio
from recipe_detail_info
group by groupname , recipe_group ,capability
),
recipegrp_detail_info as (
select a.groupname , a.recipe_group , a.recipe , a.productfamily ,a.capability , a.stagename , a.if_recipe_active , a.MPS_Ratio , a.tgtuptime , a.tgtme , a.wph , a.k_unit ,
a.admin_flag , nvl(d.dedicate_tool_count,0) dedicate_tool_count , nvl(case when demand!=0 then d.dedicate_tool_count/a.demand end,0) dedicate_ratio ,
c.plan_rls , case when demand >=1 then c.plan_rls / demand when demand <1 and demand>0 then c.plan_rls / 1 end plan_path , r.Plan_total_ratio ,
c.ACT_rls , case when demand >=1 then c.ACT_rls / demand when demand <1 and demand>0 then c.ACT_rls / 1 end act_path , r.act_total_ratio ,
a.mps_modify , a.rank
from (
select groupname , recipe_group ,
rtrim(regexp_replace(xmlagg(XMLparse(content to_char(recipe)||',' )order by to_char(recipe) ).getclobval(),'([^,]+)(,\1)+','\1'),',') recipe,
rtrim(regexp_replace(xmlagg(XMLparse(content to_char(productfamily)||',' )order by to_char(productfamily) ).getclobval(),'([^,]+)(,\1)+','\1'),',') productfamily , capability ,
rtrim(regexp_replace(xmlagg(XMLparse(content to_char(stagename)||',' )order by to_char(stagename) ).getclobval(),'([^,]+)(,\1)+','\1'),',') stagename ,
null if_recipe_active , null MPS_Ratio , avg(tgtuptime) tgtuptime , avg(tgtme) tgtme , null wph , null k_unit , null admin_flag ,
--case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path ,
--case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio ,
--case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path ,
--case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio ,
sum(mps_modify) mps_modify , 2 rank , sum(demand) demand
from detail_info
GROUP BY groupname , recipe_group ,capability
) a left join chm_state_info_recipegrp c
on a.groupname = c.groupname and a.recipe_group = c.recipe_group
left join dedicate_info d
on a.recipe_group = d.recipegroup and a.groupname = d.eqpgroup left join recipegrp_total_ratio r
on a.recipe_group = r.recipe_group and a.groupname = r.groupname and a.capability = r.capability
),
chm_state_info_eqpgrp as (
select groupname , sum(note) Plan_rls , sum(is_ppid_enable) ACT_rls
from (
select groupname , eqpid , nvl(max(is_ppid_enable),'0') is_ppid_enable, nvl( max(note) ,'0') note
from temp_chm_state_info
group by groupname , eqpid
)
group by groupname
),
--by Eqp group plan/act路宽汇总: by recipe group 汇总的路宽结果再用MPS加权平均
eqpgrp_path as (
select groupname , capability ,
case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path ,
case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path
from recipegrp_detail_info
group by groupname , capability
),
--by eqp group的plan/act整机ratio:用recipe group整机ratio结果按MPS加权平均
eqpgrp_total_ratio as (
select groupname , capability ,
case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio ,
case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio
from recipegrp_detail_info
group by groupname , capability
),
dedicate_info_eqpgrp as (
select eqpgroup , sum(dedicate_tool_count) dedicate_tool_count
from dedicate_info
group by eqpgroup
),
tmp_eqpgrp_detail_info as (
select groupname ,
--rtrim(regexp_replace(xmlagg(XMLparse(content recipe_group||',' )order by recipe_group ).getclobval(),'([^,]+)(,\1)+','\1'),',') recipe_group ,
rtrim(xmlagg(xmlparse(content recipe_group||',') order by recipe_group).getclobval(),',') recipe_group ,
rtrim(regexp_replace(xmlagg(XMLparse(content recipe||'/' )order by recipe ).getclobval(),'([^,]+)(,\1)+','\1'),',') recipe ,
rtrim(regexp_replace(xmlagg(XMLparse(content productfamily||',' )order by productfamily ).getclobval(),'([^,]+)(,\1)+','\1'),',') productfamily , capability ,
rtrim(regexp_replace(xmlagg(XMLparse(content stagename||',' )order by stagename ).getclobval(),'([^,]+)(,\1)+','\1'),',') stagename ,
null if_recipe_active , null MPS_Ratio , avg(tgtuptime) tgtuptime , avg(tgtme) tgtme , null wph , null k_unit , null admin_flag ,
--case when sum(mps_modify)>0 then sum(mps_modify*act_total_ratio)/sum(mps_modify) end act_total_ratio ,
--case when sum(mps_modify)>0 then sum(mps_modify*Plan_total_ratio)/sum(mps_modify) end Plan_total_ratio ,
--case when sum(mps_modify)>0 then sum(mps_modify*plan_path)/sum(mps_modify) end plan_path ,
--case when sum(mps_modify)>0 then sum(mps_modify*act_path)/sum(mps_modify) end act_path ,
sum(mps_modify) mps_modify , 1 rank , sum(demand) demand
from detail_info
GROUP BY groupname , capability
),
eqpgrp_detail_info as (
select s.groupname ,s.recipe_group ,s.recipe , s.productfamily , s.capability ,stagename ,if_recipe_active , MPS_Ratio , tgtuptime , tgtme , wph , k_unit ,
nvl(r2.note,'Y') admin_flag , nvl(d.dedicate_tool_count,0) dedicate_tool_count,
nvl(case when demand!=0 then d.dedicate_tool_count/s.demand end,0) dedicate_ratio , c.plan_rls , e.plan_path , r.Plan_total_ratio ,
c.act_rls , e.act_path , r.act_total_ratio , mps_modify , 1 rank
from tmp_eqpgrp_detail_info s LEFT JOIN P_MFG_CREATE.RPT_TGT_RAP_STATICSTATE_CONFIG r2
ON r2.category ='是否需要路宽管理'
and s.groupname = r2.eqpgroup left join chm_state_info_eqpgrp c
on s.groupname = c.groupname
left join dedicate_info_eqpgrp d
on s.groupname = d.eqpgroup left join eqpgrp_path e
on s.groupname = e.groupname and s.capability = e.capability left join eqpgrp_total_ratio r
on s.groupname = r.groupname and s.capability = r.capability
)
select recipe
from recipegrp_detail_info
union all
select recipe
from eqpgrp_detail_info;