FireBird Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
파이어버드 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
IBPhoenix
FireBird Main site
볼랜드포럼 광고 모집

FireBird Q&A
[2746] TRIM 시 탭문자 제거 되지 않는 문제
최락중 [] 2396 읽음    2008-03-20 19:23
안녕하세요.

연속해서 질문을 하게되네요. 모르는 것이 많아서..ㅡㅡ;

탭으로 구분된 TEXT 파일을 DB로 불러오려고 합니다.
여러가지 방법(Query, Table, Stored Procedure 등) 시도하다가
Firebird FAQ 사이트에서 아래와 같은 방법을 발견하고 적용했더니 빠르더군요.
(불러와야하는 데이터가 약 1,000만건)

DB 환경:
  OS: Windows XP
  버전: Firebird 2.0
  Char-set : KSC_5601
  툴 : DELPHI 7 + ZEOS
 
불러오는 중 문제가 2가지 있었는데
하나는 데이터 타입의 'Char'가 몇 Byte인지 왔다 갔다 하는 것과 (확실히 1Byte는 아니더군요)
구분자로 쓰인 탭문자입니다.

첫번째 문제는 무식하게 Field Size를 조정해서 맞췄구요. (여러번의 시행착오...)

탭문자가 문제로 남았습니다. 이게 Trim으로 해도 없어지질 않네요.
문서에 보니 Trim할 문자를 정할 수 있는 것 같은데, 탭은 어떻게 입력해야하는지 자세한 정보가 없습니다.

예를 들면 아래와 같습니다. (탭문자 '탭', 공백 'B'로 표현)

TEXT FILE 구조

field1                 field2              field3
----------       ----------     ----------
12345BBBBB탭12345BBBBB탭12345BBBBB
...
...
...

CREATE TABLE ext1 EXTERNAL 'c:\myfile.txt'
(
field1 char(5),
field2 char(5),
field3 char(5)
);
이렇게 하면 filed2, field3에 탭문자가 들어갑니다.
field2 ==> '탭12345'

INSERT INTO ....
select trim(field1), trim(field2), .... from ext1
Trim으로 없애려고 해도 안되고

그렇다고 필드 사이에 더미 필드를 만들면 탭문자와 다음 필드의 첫번째 문자가 더미 필드로 들어 갑니다.
CREATE TABLE ext1 EXTERNAL 'c:\myfile.txt'
(
field1 char(5),
dummy1 char(1),
field2 char(5),
dummy1 char(1),
field3 char(5)
);
dummy1 ==> '탭1'

결국은 trim이 되던지, 아니면 Byte단위로 Field size를 조정할 수 있던지 해야 할 것 같습니다.

정신 없이 써서 이해가 되실지 모르겠네요. 고수여러분의 답변을 부탁드립니다.

==========================================================================================
Is there some bulk load or other way to import a lot of data fast?

Currently there is only one way to quickly load a lot of data into database. That is by using external tables. You should read the manual for details, but here's a short explanation. You create a binary or textual file using the external table format and then hook it up in the database using a statement like this:

CREATE TABLE ext1 EXTERNAL 'c:\myfile.txt'
(
field1 char(20),
field2 smallint
);

To do quick import into regular table, do something like this:

INSERT INTO realtable1 (field1, field2)
SELECT field1, field2 FROM ext1;

This insert would still check constraints, foreign keys, fire triggers and build indexes. If you can, it is wise to deactivate indexes and triggers while loading and activate them when done.

Make sure you drop the external table when done, in order to release the lock on the file (see FAQ #90 for details).

The main problem with external tables is handling of NULLs and BLOBs. If you need to deal with those, you're better off using some tool like FBExport. However, please note that external tables are much faster.

+ -

관련 글 리스트
2746 TRIM 시 탭문자 제거 되지 않는 문제 최락중 2396 2008/03/20
2747     Re:TRIM 시 탭문자 제거 되지 않는 문제 최락중 2471 2008/03/21
2751         Re:Re:TRIM 시 탭문자 제거 되지 않는 문제 최락중 2528 2008/03/21
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.