728x90
반응형

동시성 제어를 위한 의사컬럼 ORA_ROWSCN


1. 의사컬럼 ORA_ROWSCN

  oracle 10g부터 제공되는 동시성 제어를 위한 의사컬럼

 

사용예)

select   a.c2, a.ora_rowscn

into       :c2, :rowscn

from      xxx a

where   key1 = :k1

;

 

update xxx set c2 = 111

where   key1 = :k1 

and      ora_rowscn = :rowscn

;

 

if (sqlca.sqlcode == 1403) {

    printf("다른 사용자에 의해 변경되었습니다...\n");

}

 

2. 추가적으로 scn_to_timestamp(ora_rowscn) 함수

scn_to_timestamp 함수는 ora_rowscn의 타임스템프를 리턴한다.

단, sys.smon_scn_time 테이블을 기반으로 구현 되었으므로

해당 테이블의 삭제 주기인 5일이 경과하면 일시를 알 수 없게 되며

ora-8181오류가 발생한다.

 

3. autonomous 트란잭션 (sub commit)

 

stored procedure 내에서 pragma autonomous_transaction을 사용하여

서브커밋을 구현 할 수 있음.

 

예)

create or replace function xxx (aa number) return number

as

pragma autonomous_transaction;

 

begin

  update ...

  ;

 

  commit;

  return n;

end;

 

위의 펑션을 사용하는 프로그램은 위 스토어드 프로시져 내에서의 커밋에

영향을 받지 아니한다.

 

 

참고 : 오라클 성능 고도화 해법 - 조시형[b2en] 

 

728x90
반응형

+ Recent posts