2011-10-14 11:23:02
SQL 4 Oracle 오라클용 sql 실무
▒ PLSQL- DATA가 있으면 UPDATE, 없으면 INSERT
declare
P_cnt number := 0;
find_CNT number := 0;
cursor P_cursor is
select 고객ID, 고객상태, 취득년월일, 취득점수
from 목적_Table
where 취득년월일 = '20111001'
;
begin
for box in P_cursor loop
select count(*) into P_cnt
from 평가_Table
where 고객ID = box.고객ID
and 취득년월일 = box.취득년월일
;
IF P_cnt = 0 then
insert into 평가_Table
values(box.고객ID
,box.고객상태
,box.취득년월일
,box.취득점수)
;
ELSE
update 평가_Table
set 고객상태 = box.고객상태 ,
취득점수 = box.취득점수
where 고객ID = box.고객ID
and 취득년월일 = box.취득년월일
;
END IF;
find_CNT := find_CNT + 1;
IF mod(find_CNT,1000) = 0 then
commit;
-- dbms_output.put_line('** modification COUNT : '|| find_CNT);
END IF;
end loop;
commit;
end;

'SQL4Oracle' 카테고리의 다른 글
| PROCEDURE 상태체크 (0) | 2023.03.10 |
|---|---|
| TABLESPACE 당 사용율 조회 (0) | 2023.03.10 |
| 메인 Table 안에서 OVER함수 이용 다중고객 계산하기 (0) | 2023.03.10 |
| replace가 꼭 필요한 시점 (0) | 2023.03.10 |
| 재미있는 DUAL 테이블2 (0) | 2023.03.10 |