[20130301]clob字段的empty_clob与NULL.txt

[20130301]clob字段的empty_clob与NULL.txt

工作需要,开始研究一下clob字段.看看函数empty_clob()与null的区别.

1.建立测试环境:
SQL> select * from v$version where rownum<=1;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

SQL> select * from v$nls_parameters where parameter='NLS_CHARACTERSET';

PARAMETER           VALUE     
------------------- ---------
NLS_CHARACTERSET    ZHS16GBK

--安装的语言选择NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK

create table t ( id number,c clob);
insert into t values (1,empty_clob());
insert into t values (2,NULL);
commit ;

SQL> column c format a30
SQL> select rowid,t.* from t ;

ROWID                      ID C
------------------ ---------- ------------------------------
AABB0EAAEAAAAWeAAA          1
AABB0EAAEAAAAWeAAB          2

SQL> @lookup_rowid AABB0EAAEAAAAWeAAA

    OBJECT       FILE      BLOCK        ROW
---------- ---------- ---------- ----------
    269572          4       1438          0

--保证写到磁盘.
SQL> alter system checkpoint;
System altered.

2.使用bbed观察:
BBED> set dba   4,1438
        DBA             0x0100059e (16778654 4,1438)

BBED> map /v
 File: /u01/app/oracle11g/oradata/test/users01.dbf (4)
 Block: 1438                                  Dba:0x0100059e
------------------------------------------------------------
 KTB Data Block (Table/Cluster)

 struct kcbh, 20 bytes                      @0
    ub1 type_kcbh                           @0
    ub1 frmt_kcbh                           @1
    ub1 spare1_kcbh                         @2
    ub1 spare2_kcbh                         @3
    ub4 rdba_kcbh                           @4
    ub4 bas_kcbh                            @8
    ub2 wrp_kcbh                            @12
    ub1 seq_kcbh                            @14
    ub1 flg_kcbh                            @15
    ub2 chkval_kcbh                         @16
    ub2 spare3_kcbh                         @18

 struct ktbbh, 72 bytes                     @20
    ub1 ktbbhtyp                            @20
    union ktbbhsid, 4 bytes                 @24
    struct ktbbhcsc, 8 bytes                @28
    sb2 ktbbhict                            @36
    ub1 ktbbhflg                            @38
    ub1 ktbbhfsl                            @39
    ub4 ktbbhfnx                            @40
    struct ktbbhitl[2], 48 bytes            @44

 struct kdbh, 14 bytes                      @100
    ub1 kdbhflag                            @100
    sb1 kdbhntab                            @101
    sb2 kdbhnrow                            @102
    sb2 kdbhfrre                            @104
    sb2 kdbhfsbo                            @106
    sb2 kdbhfseo                            @108
    sb2 kdbhavsp                            @110
    sb2 kdbhtosp                            @112

 struct kdbt[1], 4 bytes                    @114
    sb2 kdbtoffs                            @114
    sb2 kdbtnrow                            @116

 sb2 kdbr[2]                                @118

 ub1 freespace[8017]                        @122

 ub1 rowdata[49]                            @8139

 ub4 tailchk                                @8188

BBED> p *kdbr[1]
rowdata[0]
----------
ub1 rowdata[0]                              @8139     0x2c

BBED> x /2rnc
rowdata[0]                                  @8139
----------
flag@8139: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8140: 0x01
cols@8141:    1

col    0[2] @8142: 2

rowdata[6]                                  @8145
----------
flag@8145: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8146: 0x01
cols@8147:    2

col    0[2] @8148: 1
col   1[36] @8151: .T.................s................

--可以发现两者存在不同,empty_clob()并占用36字节[如果加上前面的长度指示器,占用37字节],而NULL不占用空间.

BBED> p  *kdbr[0]
rowdata[6]
----------
ub1 rowdata[6]                              @8145     0x2c

BBED> x /r
rowdata[6]                                  @8145
----------
flag@8145: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8146: 0x01
cols@8147:    2

col    0[2] @8148:  0xc1  0x02
col   1[36] @8151:  0x00  0x54  0x00  0x01  0x02  0x0c  0x80  0x00  0x00  0x02
                    0x00  0x00  0x00  0x01  0x00  0x00  0x01  0xdd  0xf4  0x73 
                    0x00  0x10  0x09  0x00  0x00  0x00  0x00  0x00  0x00  0x00  
                    0x00  0x00  0x00  0x00  0x00  0x00

SQL> alter system dump datafile 4 block 1438;
System altered.

--看看转储文件:
Block header dump:  0x0100059e
 Object id on Block? Y
 seg/obj: 0x41d04  csc: 0x00.c010a962  itc: 2  flg: E  typ: 1 - DATA
     brn: 0  bdba: 0x1000598 ver: 0x01 opc: 0
     inc: 0  exflg: 0

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
0x01   0x0005.020.00003023  0x00c006e2.1675.0a  --U-    2  fsc 0x0000.c010a966
0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000
bdba: 0x0100059e
data_block_dump,data header at 0x2a972c5264
===============
tsiz: 0x1f98
hsiz: 0x16
pbl: 0x2a972c5264
     76543210
flag=--------
ntab=1
nrow=2
frre=-1
fsbo=0x16
fseo=0x1f67
avsp=0x1f4e
tosp=0x1f4e
0xe:pti[0]  nrow=2  ffs=0
0x12:pri[0] ffs=0x1f6d
0x14:pri[1] ffs=0x1f67
block_row_dump:
tab 0, row 0, @0x1f6d
tl: 43 fb: --H-FL-- lb: 0x1  cc: 2
col  0: [ 2]  c1 02
col  1: [36]                    <== 这里我重新排了一下版.
 00 54 00 01 02 0c 80 00 00 02  <== Header 占10bytes
 00 00 00 01 00 00 01 dd f4 73  <== LOBID  占10bytes
 00 10 09 00 00 00 00 00 00 00  <== Inode  占16bytes
 00 00 00 00 00 00
LOB
Locator:
  Length:        84(36)
  Version:        1
  Byte Length:    2
  LobID: 00.00.00.01.00.00.01.dd.f4.73
  Flags[ 0x02 0x0c 0x80 0x00 ]:
    Type: CLOB
    Storage: BasicFile
    Enable Storage in Row
    Characterset Format: IMPLICIT
    Partitioned Table: No
    Options: VaringWidthReadWrite
  Inode:
    Size:     16
    Flag:     0x09 [ Valid DataInRow ]
    Future:   0x00 (should be '0x00')
    Blocks:   0
    Bytes:    0
    Version:  00000.0000000000
    Inline data[0]
Dump of memory from 0x0000002A972C71FC to 0x0000002A972C71FC
tab 0, row 1, @0x1f67
tl: 6 fb: --H-FL-- lb: 0x1  cc: 1
col  0: [ 2]  c1 03
end_of_block_dump
End dump data blocks tsn: 4 file#: 4 minblk 1438 maxblk 1438

--11G版本转储的显示很清晰:

Header 占10bytes   : 00 54 00 01 02 0c 80 00 00 02
LOBID  占10bytes   : 00 00 00 01 00 00 01 dd f4 73
. LOB ID is a 10 byte number identifying individual instance of a LOB
. Allocated when LOB value is created including EMPTY_CLOB() etc
. Format is  where
      is a currently unknown 4-byte number (always 1)
      is a 6-byte number generated from sequence SYS.IDGEN1$

SQL> @16to10  01ddf473
16 to 10 DEC
------------
    31323251

SQL> select * from dba_sequences where sequence_owner='SYS' and sequence_name ='IDGEN1$';

SEQUENCE_OWNER                 SEQUENCE_NAME                   MIN_VALUE  MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER
------------------------------ ------------------------------ ---------- ---------- ------------ - - ---------- -----------
SYS                            IDGEN1$                                 1 1.0000E+28           50 N N       1000    31323651

Inode 占用16bytes
Body Length占2bytes: 00 10     => 等于16也就是36-前面的20字节(header的长度+lobid的长度)=16.
Flags      占2bytes: 09 00
LOB Length 占6bytes: 00 00 00 00 00 00      ==>empty_clob() 长度为0,clob自身长度为0
Version    占6bytes: 00 00 00 00 00 00


总结:
1.从以上可以看出,clob字段NULL与empty_clob()是不同的。
2.如果clob字段有信息,除了保存信息外额外要消耗36字节来保存相关信息。
3.其他问题看后续的帖子。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-755269/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-755269/

这个是原本的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;
最新发布
09-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值