標籤

4GL (1) 人才發展 (10) 人物 (3) 太陽能 (4) 心理 (3) 心靈 (10) 文學 (31) 生活常識 (14) 光學 (1) 名句 (10) 即時通訊軟體 (2) 奇狐 (2) 音樂 (2) 產業 (5) 郭語錄 (3) 無聊 (3) 統計 (4) 新聞 (1) 經濟學 (1) 經營管理 (42) 解析度 (1) 遊戲 (5) 電學 (1) 網管 (10) 廣告 (1) 數學 (1) 機率 (1) 雜趣 (1) 證券 (4) 證券期貨 (1) ABAP (15) AD (1) agentflow (4) AJAX (1) Android (1) AnyChart (1) Apache (14) BASIS (4) BDL (1) C# (1) Church (1) CIE (1) CO (38) Converter (1) cron (1) CSS (23) DMS (1) DVD (1) Eclipse (1) English (1) excel (5) Exchange (4) Failover (1) FI (57) File Transfer (1) Firefox (2) FM (2) fourjs (1) gladiatus (1) google (1) Google Maps API (2) grep (1) Grub (1) HR (2) html (23) HTS (8) IE (1) IE 8 (1) IIS (1) IMAP (3) Internet Explorer (1) java (3) JavaScript (22) jQuery (6) JSON (1) K3b (1) LED (3) Linux (112) Linux Mint (4) Load Balance (1) Microsoft (2) MIS (2) MM (51) MSSQL (1) MySQL (27) Network (1) NFS (1) Office (1) Oracle (125) Outlook (3) PDF (6) Perl (59) PHP (33) PL/SQL (1) PL/SQL Developer (1) PM (3) Postfix (2) postfwd (1) PostgreSQL (1) PP (50) python (1) QM (1) Red Hat (4) Reporting Service (28) ruby (11) SAP (234) scp (1) SD (16) sed (1) Selenium-WebDriver (5) shell (5) SQL (4) SQL server (8) SQuirreL SQL Client (1) SSH (2) SWOT (3) Symantec (2) T-SQL (7) Tera Term (2) tip (1) tiptop (22) Tomcat (6) Trouble Shooting (1) Tuning (5) Ubuntu (33) ufw (1) utf-8 (1) VIM (11) Virtual Machine (2) vnc (3) Web Service (2) wget (1) Windows (19) Windows (1) WM (6) youtube (1) yum (2)

2011年5月25日 星期三

sys_refcursor with using bing variables

create or replace procedure bm_proc_capa(pWERKS varchar2,pTYPE varchar2,pSMALL_GROUP varchar2,pMPIDGROUP varchar2,
                                         pCURSOR out sys_refcursor) is
  cursor c1(aWERKS varchar2) is
  select *
    from bm_tbl_capa
   where werks = pWERKS
   order by seqno;
  
  cursor c2(aCAPA number,aWERKS varchar2,aSMALL_GROUP varchar2,aTYPE varchar2) is
  with mv as (
              select mpidgroup,cnm,equip,uph,small_group,anln1,werks,
                     vdrnm,mdlnm,locat,sprnm,opmchr,
                     sum(uph*decode(aTYPE,'5',20,'6',22)) over(partition by mpidgroup order by uph desc,opmchr desc rows between unbounded preceding and current row) upd,
                     sum(uph*decode(aTYPE,'5',20,'6',22)) over(partition by mpidgroup order by uph desc,opmchr desc rows between unbounded preceding and 1 preceding) upd1,
                     1/a.opmchr op_d,1/a.opmchr op_n
                from dwmgr.mes_vw_equip_capa a
               where small_group = aSMALL_GROUP
                 and uph is not null
                 and werks = aWERKS
                 and not exists (select null
                                   from bm_tmp_capa b
                                  where a.werks = b.werks
                                    and a.equip = b.equip
                                )
             )
  select a.*,
         max(upd) over(partition by small_group,mpidgroup) upd_max,
         b.seqno
    from mv a,dm_tbl_ktsch_seq b
   where (aCAPA between upd1 and upd or aCAPA > upd)
     and a.mpidgroup = b.ktsch(+)
   order by b.seqno,upd;
begin
  delete from bm_tmp_capa;
  for r1 in c1(pWERKS) loop
    for r2 in c2(r1.capacity,r1.werks,r1.small_group,pTYPE) loop
      insert into bm_tmp_capa(mpidgroup,cnm,equip,uph,small_group,anln1,werks,vdrnm,mdlnm,locat,sprnm,opmchr,
                              upd,upd1,op_d,op_n,upd_max,seqno
                             )
      values(r2.mpidgroup,r2.cnm,r2.equip,r2.uph,r2.small_group,r2.anln1,r2.werks,
             r2.vdrnm,r2.mdlnm,r2.locat,r2.sprnm,r2.opmchr,
             r2.upd,r2.upd1,r2.op_d,r2.op_n,r2.upd_max,r2.seqno
            );
    end loop;
  end loop;
  commit;
  open pCURSOR for 'select * from bm_tmp_capa where small_group like nullif(:small_group,''ALL'')||''%'' and mpidgroup like nullif(:mpidgroup,''ALL'')||''%''' using pSMALL_GROUP,pMPIDGROUP;
end bm_proc_capa;

沒有留言:

張貼留言