현상
SQL 확장자로 작성된 쿼리 파일을 tbsql 클라이언트에서 @파일명 형식으로 실행할 때, insert 또는 select 결과값에 한글이 포함된 경우 글자가 깨져서 출력되는 현상이 발생했습니다.
1. Insert 시도
vi test.sql
create table test (c1 varchar2(10));
INSERT INTO test VALUES ('가');
INSERT INTO test VALUES ('나');
INSERT INTO test VALUES ('다');
INSERT INTO test VALUES ('라');
INSERT INTO test VALUES ('마');
INSERT INTO test VALUES ('바');
INSERT INTO test VALUES ('사');
INSERT INTO test VALUES ('아');
INSERT INTO test VALUES ('자');
INSERT INTO test VALUES ('차');
INSERT INTO test VALUES ('카');
INSERT INTO test VALUES ('타');
INSERT INTO test VALUES ('파');
INSERT INTO test VALUES ('하');
commit;
SQL
복사
2. 결과
SQL> @test
Table 'TEST' created.
1 row inserted.
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
1 row inserted.
TBR-23002: Missing single quote.
at line 1, column 34 of null:
TBR-23002: Missing single quote.
at line 1, column 34 of null:
Commit completed.
SQL
복사
원인
해당 현상의 원인은 DB 캐릭터셋과 OS의 문자 인코딩 설정이 일치하지 않기 때문입니다. 이로 인해 tbsql에서 한글 데이터를 제대로 인식하거나 출력하지 못해 깨진 문자로 보이게 됩니다.
해결
아래 사항들을 수정합니다.
참고
DB 캐릭터셋이 UTF8일 경우의 예시입니다.
1.
개인 PC에서 test.sql 파일 작성 후, 인코딩 UTF8로 저장합니다. Notepad++와 같은 도구를 사용하여 인코딩을 확인합니다.
2.
개인 PC의 test.sql파일을 DB서버로 복사합니다,
3.
DB 서버의 os locale를 ko_KR.utf8로 설정합니다.
4.
DB 서버에 접속하는 원격 접속 툴의 인코딩 방식(UTF8)로 설정합니다.
ex:) putty의 설정 중, Windows -> Translation -> Remote character set : UTF-8
5.
$TB_HOME/client/config/tbdsn.tbr파일의 마지막 줄에 TB_NLS_LANG=UTF8 추가합니다.
6.
스크립트(@test.sql)를 수행합니다.
수행 예시
SQL> @test
Table 'TEST' created.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
1 row inserted.
Commit completed.
SQL> SELECT * FROM TEST;
C1
ㅡㅡ
가
나
다
라
마
바
사
아
자
차
카
타
파
하
14 rows selected.
SQL>
SQL
복사