sql递归展BOM

tiptop

WITH t AS ( SELECT SYS_CONNECT_BY_PATH(a.bmb01,'|')||'|'||a.bmb03||'|' as path
,SYS_CONNECT_BY_PATH(a.bmb06,'|')||'|' as qty_path,bmb06,bmb10
FROM bmb_file a
START WITH a.bmb01 = :ITEM
AND a.bmb04 <= sysdate AND (a.bmb05 > sysdate or a.bmb05 is null)
CONNECT BY a.bmb01 = PRIOR a.bmb03 AND a.bmb04 <= sysdate AND (a.bmb05 > sysdate or a.bmb05 is null) )

SELECT G_CODE_CP,a.ima02 aima02,a.ima021 aima021,G_CODE_LJ,b.ima02 bima02,b.ima021 bima021,bmb10,SUM(DEC_CM) AS DEC_CM
FROM (SELECT SUBSTR(path,2,INSTR(path,'|',1,2)-INSTR(path,'|',1,1)-1) as G_CODE_CP
,SUBSTR(path,INSTR(path,'|',-1,2)+1,INSTR(path,'|',-1,1)-INSTR(path,'|',-1,2)-1) as G_CODE_LJ
,(SELECT EXP(SUM(LN(SUBSTR(qty_path,INSTR(qty_path,'|',1,rn)+1,INSTR(qty_path,'|',1,rn+1)-INSTR(qty_path,'|',1,rn)-1))))
FROM (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM<=100)
WHERE SUBSTR(qty_path,INSTR(qty_path,'|',1,rn)+1,INSTR(qty_path,'|',1,rn+1)-INSTR(qty_path,'|',1,rn)-1) IS NOT NULL
) AS DEC_CM,bmb10  FROM t )
LEFT OUTER JOIN ima_file a on a.ima01 =G_CODE_CP
LEFT OUTER JOIN ima_file b on b.ima01 =G_CODE_LJ
GROUP BY G_CODE_CP,a.ima02,a.ima021,b.ima02,b.ima021,bmb10,G_CODE_LJ;

T100

WITH t AS ( SELECT SYS_CONNECT_BY_PATH(a.bmba001,'|')||'|'||a.bmba003||'|' as path
,SYS_CONNECT_BY_PATH((a.bmba011/a.bmba012),'|')||'|' as qty_path,bmba011,bmba010
FROM bmba_t a
START WITH a.bmba001 =:ITEM and a.bmbaent=:ENT and bmbasite=:SITE
AND a.bmba005 <= sysdate AND (a.bmba006 > sysdate or a.bmba006 is null)
CONNECT BY a.bmba001 = PRIOR a.bmba003 AND a.bmba005 <= sysdate AND (a.bmba006 > sysdate or a.bmba006 is null) )

SELECT G_CODE_CP,aa.imaal003,aa.imaal004,G_CODE_LJ,bb.imaal003,bb.imaal004,bmba010,SUM(DEC_CM) AS DEC_CM
FROM (SELECT SUBSTR(path,2,INSTR(path,'|',1,2)-INSTR(path,'|',1,1)-1) as G_CODE_CP
,SUBSTR(path,INSTR(path,'|',-1,2)+1,INSTR(path,'|',-1,1)-INSTR(path,'|',-1,2)-1) as G_CODE_LJ
,(SELECT EXP(SUM(LN(SUBSTR(qty_path,INSTR(qty_path,'|',1,rn)+1,INSTR(qty_path,'|',1,rn+1)-INSTR(qty_path,'|',1,rn)-1))))
FROM (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM<=100)
WHERE SUBSTR(qty_path,INSTR(qty_path,'|',1,rn)+1,INSTR(qty_path,'|',1,rn+1)-INSTR(qty_path,'|',1,rn)-1) IS NOT NULL
) AS DEC_CM,bmba010  FROM t )
left outer join imaal_t aa on aa.imaalent=:ENT and aa.imaal001=G_CODE_CP and aa.imaal002='zh_CN'
left outer join imaal_t bb on bb.imaalent=:ENT and bb.imaal001=G_CODE_LJ and bb.imaal002='zh_CN'
GROUP BY G_CODE_CP,aa.imaal003,aa.imaal004,bb.imaal003,bb.imaal004,bmba010,G_CODE_LJ;

你可能感兴趣的:(tiptop,oracle)