TECH
QUESTION
자주하는 질문답변 입니다.
Oracle
작성자 | 유건데이타 | 등록일 | 2015-07-15 |
제목 | 많은 개수의 TABLE을 한번에 TABLE 별로 EXPORT받는 방법 | ||
---|---|---|---|
많은 개수의 TABLE을 한번에 TABLE 별로 EXPORT받는 방법
===================================================== Purpose ------- export를 table 별로 받아야 하는 데, export를 받아야 할 table이 매우 많은 경우 tables option에 모두 적는 것이 불가능한 경우가 있다. 이러한 경우에 대해 보다 쉽게 작업할 수 있는 방법을 알아보자. Explanation ----------- 1. sqlplus scott/tiger로 login SQL> set heading off SQL> set pagesize 5000 (user가 소유한 table의 갯수이상) SQL> spool scott.out SQL> select tname from tab; SQL> exit 2. 위와 같이하면 모든 scott user의 table들이 scott.out에 저장 $ vi scott.out SQL> select tname from tab; BONUS DEPT DUMMY EMP SALGRADE SQL> exit vi editor로 불필요한 처음과 마지막 두라인 삭제후 table 이름뒤에 있는 null문자를 제거 한다. < null문자 제거 및 export 화일을 만드는 사전 작업 > 화일을 open 한 후 1) :g/ /s///g <--- table name뒤의 null문자 제거 2) :1 3) bonus table 뒤에 comma 를 append 4) :map @ j$. 하고 Enter <--- 다음 라인에도 2번의 작업을 하기 위한 macro 5) Shift+2 (계속 누르고 있음)<--- 다음 라인의 마지막에 comma 추가 6) 제일 마지막 라인은 comma 불필요 위의 out file을 100 개씩(table name이 길 경우는 그 이하로) 라인을 쪼개어 화일을 나누어 개별 화일 이름을 부여하여 저장한다. 예) 1~100은 scott1.out 101~200은 scott2.out .....과 같이 나누고 화일의 제일 마지막 라인의 comma를 제거 아래의 script4exp.c를 compile하여 export를 위한 shell script를 작성한다. ( 필요하다면 script내의 export option을 수정하여 compile) compile이 끝난후 $ script4exp scott1.out scott1.sh scott tiger scott1.dmp scott1.log $ script4exp scott2.out scott2.sh scott tiger scott2.dmp scott2.log . . . 하게 되면 scott1.sh, scott2.sh,.....가 생기며 이를 모드를 바꿔 background job으로 수행하면 된다. 주의) 1. 작업이 끝난후 *.sh의 file size를 check 한다. 2. 가능한 큰 table은 outfile에서 빼내 따로 export한다. ====script4exp.c================= #include #include #define EXPCMD "exp %s/%s buffer=52428800 file=%s log=%s tables=" main(int argc, char **argv) { FILE ifp, ofp; char buff[256], *pt; if (argc != 7) { printf("\nUSAGE :\n"); printf("$ script4exp infile.out, outfile.sh, username, passwd, dmpfile.dmp, logfile.log\n\n"); exit(0); } if ((ifp = fopen(argv[1], "r")) == NULL) { printf("%s file open fail !!\n", argv[1]); exit(0); } if ((ofp = fopen(argv[2], "w")) == NULL) { printf("%s file open fail !!\n", argv[1]); exit(0); } fprintf(ofp, EXPCMD, argv[3], argv[4], argv[5], argv[6]); while((fgets(buff, 80, ifp)) != NULL) { if ((pt = strchr(buff, '\n')) != NULL) *pt = NULL; fprintf(ofp, "%s", buff); memset(buff, 0, sizeof(buff)); } fprintf(ofp, "\n"); fclose(ifp); fclose(ifp); } |
Comment | |||
---|---|---|---|
등록된 코멘트가 없습니다. |