[PL/SQL] Cursor 를 이용한 Loop 의 예
IT 2008/05/08 12:18 |declare
t_hispay pa_hispay%rowtype;
cursor cur_hispay is
select payym, paytype from pa_hispay
where compcd = 'C31'
and corpcd = 'C31EC03'
and payym < '20060101'
group by payym, paytype
;
begin
open cur_hispay;
loop
fetch cur_hispay into t_hispay.payym, t_hispay.paytype;
exit when cur_hispay%NOTFOUND;
Insert into paysum1t_tsdi
(YYYYMM, EMP_ID, PAYGBN, NAME, DEPT,DEPTNM, COSTCT, COSTNM,WORKCT, JG, JL, JLNM,
JIKCHAKCD,JIKCHAKNM,JOBCD,JOBNM,
EMP_STATUS,EMP_STATUSNM, CON_INC,
BASIC_SAL, WAGES, INS_GRADE, PROMOTION_WAGES,
WORK_OT1, WORK_OT2, WORK_OT3, SHIFT_NO, SHIFT_NO2, LATE_MIN,
EARLY_MIN, LATE3, UP_LEAVE1, UP_LEAVE2, UP_LEAVE3,
UP_LEAVE10, UP_LEAVE11, LATE_NO, EARLY_NO,
GROSS, GROSS_BASIC, GROSS_PI, DEDUCE,
NET, NET_BASIC, NET_PI,
NIGHT1, NIGHT2, NIGHT3,
JIKCHAK, BOKRI,
GAEBAL, GYEJUL, JANUP1, JANUP2, JANUP3,
DANGJIK1, DANGJIK2, MANGEUN, JAGYUK,
YABAN, SOGUB, SOGUB_B, ETC,
TAX, ROOM, ELECTRIC, WATER, FOOD,
YANGRO, YANGRO_C, MEDI, MEDI_C, SILUP, SILUP_C, GONGSANG, GONGSANG_C, JUTAK,
JUTAK_C, SAENGYUK, SAENGYUK_C,
INS1_YN, INS2_YN, INS3_YN, INS4_YN, INS5_YN, INS6_YN, DUE_INC,
GITA_SUDANG1, OVER_PAY, ADD_PAY, OVER_TIME,
ALLOWANCE_OTHER, G3HOURSE,
G3TECH, AWADAY, MULCT, GONGLING, UP_LEAVE4, PEND_YN, GRADE, ST_BASICSAL,
ST_PROSAL, GANGSA,acc_no)
Select substr(a.payym,1,6),a.idno,a.paytype,a.name,a.deptcd,a.deptnm,a.cocecd,a.cocenm,
'',substr(a.jobcd,1,1),a.jikgubcd,a.jikgubnm,
a.jikchakcd,a.jikchaknm,a.jobcd,a.jobnm,
a.statuscd,a.statusnm,a.susubyn,
nvl(b.basic_sal,0),nvl(b.wages,0),nvl(a.insustdamt,0),nvl(b.promotion_wages,0),
nvl(d.minot1,0),nvl(d.minot2,0),nvl(d.legot,0),nvl(d.shiftno,0),0,nvl(d.latemin,0),
nvl(d.earlymin,0),nvl(d.outtime,0),nvl(d.upleave1,0),nvl(d.upleave2,0),nvl(d.upleave3,0),
nvl(d.upleave10,0),nvl(d.upleave11,0),nvl(d.latecnt,0),nvl(d.earlycnt,0),
nvl(a.allowtotamt,0),0 gross_basic,0 gross_pi,nvl(a.dedtotamt,0) - nvl(c.mulct,0),
nvl(a.diffpayamt,0) + nvl(c.mulct,0),0 net_basic,0 net_pi,
nvl(d.night1,0),nvl(d.night2,0),nvl(d.night3,0),
nvl(b.jikchak,0),nvl(b.bokri,0),
nvl(b.gaebal,0),nvl(b.gyejul,0),nvl(b.janup1,0),nvl(b.janup2,0),nvl(b.janup3,0),
nvl(b.dangjik1,0),nvl(b.dangjik2,0),nvl(b.mangeun,0),nvl(b.jagyuk,0),
nvl(b.yaban,0),nvl(b.sogub,0),nvl(c.sogub_b,0),0 etc,
nvl(c.tax,0),nvl(c.room,0),nvl(c.electric,0),nvl(c.water,0),nvl(c.food,0),
nvl(c.yangno,0),nvl(c.yangno_c,0),nvl(c.medi,0),nvl(c.medi_c,0),nvl(c.silup,0),
nvl(c.silup_c,0),nvl(c.gongsang,0),nvl(c.gongsang_c,0),nvl(c.jutak,0),
nvl(c.jutak_c,0),nvl(c.saengyuk,0),nvl(c.saengyuk_c,0),
a.revmedyn,a.revrestyn,a.revcareyn,a.revpenyn,a.partyyn,a.employn,a.susubtodt,
0 gita_sudang1,nvl(b.overpay,0),nvl(b.addpay,0),0 over_time,
nvl(b.allowance_other,0),0 g3house,
nvl(b.g3tech,0),nvl(b.awaday,0),nvl(c.mulct,0),nvl(b.gongling,0),
nvl(d.upleave4,0),nvl(a.futayn,'N'),a.hobong,0 st_basicsal,0 st_prosal,
nvl(b.gangsa,0),a.accno
From pa_hispay a,
(Select idno,
nvl(sum(decode(substr(allowinc,8,1),'A',nvl(stdamt,0))),0) basic_sal,
nvl(sum(decode(substr(allowinc,8,1),'A',nvl(realpayamt,0))),0) wages,
nvl(sum(decode(substr(allowinc,8,1),'B',nvl(realpayamt,0))),0) promotion_wages,
nvl(sum(decode(substr(allowinc,8,1),'H',nvl(realpayamt,0))),0) jikchak,
nvl(sum(decode(substr(allowinc,8,1),'C',nvl(realpayamt,0))),0) bokri,
nvl(sum(decode(allowcd,'D003',nvl(realpayamt,0))),0) gaebal,
nvl(sum(decode(substr(allowinc,8,1),'L',nvl(realpayamt,0))),0) gyejul,
nvl(sum(decode(allowcd,'D006',nvl(realpayamt,0))),0) janup1,
nvl(sum(decode(allowcd,'D007',nvl(realpayamt,0))),0) janup2,
nvl(sum(decode(allowcd,'D008',nvl(realpayamt,0))),0) janup3,
nvl(sum(decode(allowcd,'D009',nvl(realpayamt,0))),0) dangjik1,
nvl(sum(decode(allowcd,'D010',nvl(realpayamt,0))),0) dangjik2,
nvl(sum(decode(allowcd,'D011',nvl(realpayamt,0))),0) mangeun,
nvl(sum(decode(allowcd,'D101',nvl(realpayamt,0))),0) jagyuk,
nvl(sum(decode(allowcd,'D020',nvl(realpayamt,0))),0) yaban,
nvl(sum(decode(substr(allowinc,8,1),'N',nvl(realpayamt,0))),0) sogub,
nvl(sum(decode(allowcd,'D040',nvl(realpayamt,0))),0) overpay,
nvl(sum(decode(allowcd,'D051',nvl(realpayamt,0))),0) addpay,
nvl(sum(decode(allowcd,'D109',nvl(realpayamt,0))),0) allowance_other,
nvl(sum(decode(allowcd,'D104',nvl(realpayamt,0))),0)+
nvl(sum(decode(allowcd,'D105',nvl(realpayamt,0))),0)+
nvl(sum(decode(allowcd,'D106',nvl(realpayamt,0))),0)+
nvl(sum(decode(allowcd,'D113',nvl(realpayamt,0))),0) g3tech,
nvl(sum(decode(allowcd,'D103',nvl(realpayamt,0))),0)+
nvl(sum(decode(allowcd,'D202',nvl(realpayamt,0))),0) awaday,
nvl(sum(decode(allowcd,'D110',nvl(realpayamt,0))),0) gongling,
nvl(sum(decode(allowcd,'D108',nvl(realpayamt,0))),0)+
nvl(sum(decode(allowcd,'D112',nvl(realpayamt,0))),0) gangsa
From pa_allowhis
Where compcd = 'C31'
and corpcd = 'C31EC03'
and payym = t_hispay.payym
and paytype = t_hispay.paytype
group by idno) b,
(Select idno,
nvl(sum(decode(substr(dedinc,4,1),'G',nvl(realdedamt,0))),0) sogub_b,
nvl(sum(decode(dedcd,'C207',nvl(realdedamt,0))),0) tax,
nvl(sum(decode(dedcd,'C164',nvl(realdedamt,0))),0) room,
nvl(sum(decode(dedcd,'C163',nvl(realdedamt,0))),0) electric,
nvl(sum(decode(dedcd,'C165',nvl(realdedamt,0))),0) water,
nvl(sum(decode(dedcd,'C166',nvl(realdedamt,0))),0) food,
nvl(sum(decode(dedcd,'C201',nvl(realdedamt,0))),0) yangno,
nvl(sum(decode(dedcd,'C202',nvl(realdedamt,0))),0)+
nvl(sum(decode(dedcd,'C208',nvl(realdedamt,0))),0) medi,
nvl(sum(decode(dedcd,'C203',nvl(realdedamt,0))),0) jutak,
nvl(sum(decode(dedcd,'C204',nvl(realdedamt,0))),0) gongsang,
nvl(sum(decode(dedcd,'C205',nvl(realdedamt,0))),0) silup,
nvl(sum(decode(dedcd,'C206',nvl(realdedamt,0))),0) saengyuk,
nvl(sum(decode(dedcd,'C901',nvl(realdedamt,0))),0) yangno_c,
nvl(sum(decode(dedcd,'C902',nvl(realdedamt,0))),0) medi_c,
nvl(sum(decode(dedcd,'C903',nvl(realdedamt,0))),0) jutak_c,
nvl(sum(decode(dedcd,'C904',nvl(realdedamt,0))),0) gongsang_c,
nvl(sum(decode(dedcd,'C905',nvl(realdedamt,0))),0) silup_c,
nvl(sum(decode(dedcd,'C906',nvl(realdedamt,0))),0) saengyuk_c,
nvl(sum(decode(dedcd,'C133',nvl(realdedamt,0))),0) mulct
From pa_dedhis
Where compcd = 'C31'
and corpcd = 'C31EC03'
and payym = t_hispay.payym
and paytype = t_hispay.paytype
group by idno) c,
(Select idno,
round(nvl(max(decode(totcd,'MT02',nvl(cnt,0))),0)/60,1) minot1,
round(nvl(max(decode(totcd,'MT12',nvl(cnt,0))),0)/60,1) minot2,
round(nvl(max(decode(totcd,'MT21',nvl(cnt,0))),0)/60,1) legot,
round(nvl(max(decode(totcd,'MT31',nvl(cnt,0))),0)/60,1) unwork,
nvl(max(decode(totcd,'MC14',nvl(cnt,0))),0) shiftno,
nvl(max(decode(totcd,'MA01',nvl(cnt,0))),0) latecnt,
nvl(max(decode(totcd,'MA02',nvl(cnt,0))),0) latemin,
nvl(max(decode(totcd,'MA11',nvl(cnt,0))),0) earlycnt,
nvl(max(decode(totcd,'MA12',nvl(cnt,0))),0) earlymin,
round(nvl(max(decode(totcd,'MA31',nvl(cnt,0))),0)/60,1) outtime,
round(nvl(max(decode(totcd,'MA41',nvl(cnt,0))),0)/60,1) upleave1,
round(nvl(max(decode(totcd,'MA51',nvl(cnt,0))),0)/60,1) upleave2,
round(nvl(max(decode(totcd,'MA61',nvl(cnt,0))),0)/60,1) upleave3,
round(nvl(max(decode(totcd,'MA91',nvl(cnt,0))),0)/60,1) upleave4,
round(nvl(max(decode(totcd,'MA71',nvl(cnt,0))),0)/60,1) upleave10,
round(nvl(max(decode(totcd,'MA81',nvl(cnt,0))),0)/60,1) upleave11,
nvl(max(decode(totcd,'MC21',nvl(cnt,0))),0) night1,
nvl(max(decode(totcd,'MC22',nvl(cnt,0))),0) night2,
nvl(max(decode(totcd,'MC23',nvl(cnt,0))),0) night3
From ta_summaryresult
Where compcd = 'C31'
and corpcd = 'C31EC03'
and workym = t_hispay.payym
and paytype = t_hispay.paytype
group by idno) d
Where a.compcd = 'C31'
and a.corpcd = 'C31EC03'
and a.payym = t_hispay.payym
and a.paytype = t_hispay.paytype
and a.idno = b.idno(+)
and a.idno = c.idno(+)
and a.idno = d.idno(+)
;
end loop;
close cur_hispay;
end;

댓글을 달아 주세요