FAQ
Oracle Blob Data를 알티베이스로 Migration하는 샘플 프로그램
분류 기타 등록일 2013-07-09 조회수 4370
kobul 2005-11-25 173


Oracle Blob Data를 알티베이스로 Migration하는 샘플 프로그램
+++++++++++++++++++++++++++++++++++++++


요약
++++
오라클 Blob Data를 Online으로 이관하는 프로그램과
Offline으로 이관하는 스크립트를 첨부합니다.


Online으로 이관하는 프로그램 : src.latest.tar 참조
+++++++
여기서 Online이라 함은, Oracle과 Altibase DB에 각각 세션을 연결한 상황에서,
Oracle의 데이터를 Select하여, Altibase로 Insert한다는 의미로서 Online입니다.

Oracle은 $ORACLE_HOME/precomp/demo/proc/sample4.pc 소스를 참조했고,
Altibae는 $ALTIBASE_HOME/sample/SESC/binary.sc 소스를 참조했습니다.

1. 테이블 스키마는 다음과 같습니다.
가. Altibase
CREATE TABLE IMAGES
( name CHAR(80), length integer, binary BLOB(3096) ) ;
나. Oracle
CREATE TABLE IMAGES
( name VARCHAR2(80), length NUMBER(10) , binary BLOB ) ;

2. 실행을 하면 다음과 같이 나옵니다 .

[e450:/home/ora9/work/kobul/vote/src] ./mig
Oracle Connected.
Altibase Connected.
Do you want to create (or recreate) the IMAGES table (y/n)? n
(I)Insert a new image into the Oracle
(T)Insert a new image into the Altibase
(M)Migration an image from Oracle to Altibase
(S)Retrieve an image from Altibase to file
(R)Retrieve an image from Oracle to file
(L)ist the images stored in the Oracle
(D)elete an image from the Oracle
(Q)uit the program

Enter i, t, m, s, r, l, d or q:

가. Do you want to create (or recreate) the IMAGES table (y/n)? 단계에서
y를 입력하면 위의 테이블을 Altibase와 Oracle에 생성합니다.
나. Enter i, t, m, s, r, l, d or q: 단계에서 i를 입력하여,
오라클에 이미지 데이터를 Insert합니다.
(미리 이미지 데이터를 현재 디렉토리에 가져다 놓으면 편합니다.
단, 이미지 데이터의 최대 크기는 현재 32K입니다.)
다. Enter i, t, m, s, r, l, d or q: 단계에서 를 입력하여,
오라클 데이터를 알티베이스로 이관합니다.
라. 그 밖의 명령도 직관적으로 아실 수 있을 것으로 생각합니다.


Offline으로 이관하는 스크립트 : file_handle.tar참조
+++++++
Offline이라함은 Oracle의 Blob데이터를 UTL패키지를 이용하여, hexa형식의 OS파일을
생성한 후, 그 OS파일을 Altibase iloader를 이용하여 Altibase에 loading한다는 의미
입니다.

1. Oracle의 Blob 데이터를 다운로드하는 방법
가. 특정 Oracle 유저에서 Directory 객체를 생성합니다.
(Oracle 9.2.0부터는 UTL패키지의 UTL_FILE.OPEN에서의 파라메터중,
Directory명을 Directory 객체로 사용해도 됩니다.
또한 이 특정 유저는 Directory 객체 생성권한이 있어야 합니다.)

sqlplus> create or replace directory VOTE_DIR as '/home/vote';

나. 그 Oracle 유저에서 다음의 프로시저을 컴파일 합니다.

create or replace procedure file_handle
is
CURSOR EMP_CUR IS
SELECT name, length, binary FROM images;
blob_locator BLOB;
name varchar2(20);
length int;
fd utl_file.file_type;
begin
OPEN EMP_CUR ;
fd := UTL_FILE.FOPEN ('VOTE_DIR','down.dat','w', 4096 );

LOOP
FETCH EMP_CUR INTO name, length, blob_locator;
EXIT WHEN EMP_CUR%NOTFOUND ;
UTL_FILE.PUT( fd , name||' '||length ||' '||RAWTOHEX(blob_locator) );
UTL_FILE.NEW_LINE(fd);
END LOOP ;
UTL_FILE.FCLOSE(fd);
end;
/

다. 그 Oracle 유저에서 프로시저를 실행합니다.
sqlplus> exec file_handle()
이렇게 실행하면 /home/vote 디렉토리 밑에 down.dat라는 파일이 생깁니다.

2. Altibase에 Upload하는 방법
:위 과정에서 생긴 down.dat라는 파일을 Altibase에 iloder를 이용하여
Upload합니다. (iloader의 용법은 Altibase의 iloader메뉴얼 참조바랍니다. )

목록