본문 바로가기

System/Database

Oracle Character Set 변경 방법

Oracle Database 를 Export 받은 후 Import 할 경우 Character Set 이 서로 달라서 오류가 발생하는 경우가 종종 생긴다.

이럴 경우 Import 하는 Database 에서 Database 의 Character Set 을 변경해 주면 된다.

 

1. 현재의 Character Set 을 확인한다.

SQL> SELECT * FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER LIKE '%CHAR%'; 
PARAMETER                  VALUE                       
------------------------------------------------------ 
NLS_NCHAR_CONV_EXCP        FALSE 
NLS_NUMERIC_CHARACTERS     ., 
NLS_NCHAR_CHARACTERSET     AL16UTF16 
NLS_CHARACTERSET           AL32UTF8 

2. DBA 계정으로 로그인 한다.

# sqlplus / as sysdba
SQL*Plus: Release 12.2.0.1.0 Production on Fri Feb 7 18:40:29 2020 
Copyright (c) 1982, 2016, Oracle.  All rights reserved. 

Connected to: 
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 
SQL>

3. DB 를 Mount 까지만 한 후 시스템 설정을 변경한다.

SQL> SHUTDOWN
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> STARTUP MOUNT
ORACLE instance started.

Total System Global Area  780140544 bytes
Fixed Size                  8797632 bytes
Variable Size             574620224 bytes
Database Buffers          192937984 bytes
Redo Buffers                3784704 bytes
Database mounted.

SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
System altered.

SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
System altered.

SQL> ALTER DATABASE OPEN;
Database altered.

4. Character Set 을 변경한다.

SQL> ALTER DATABASE CHARACTER SET KO16KSC5601;
ALTER DATABASE CHARACTER SET KO16KSC5601
*
ERROR at line 1:
ORA-12712: new character set must be a superset of old character set

5. Character Set 변경이 오류 없이 변경되면 다행이지만 위와 같이 ORA-12712 오류가 발생하면 다음 옵션을 넣어 변경한다.

SQL> ALTER DATABASE CHARACTER SET INTERNAL_USE KO16KSC5601;
Database altered.

6. ORA-12719: operation requires database is in RESTRICTED mode 오류가 발생하면 다음 명령으로 ALTER 를 한후 CHARACTERSET 변경을 재시도한다.

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
System altered.

 

SQL> ALTER DATABASE CHARACTER SET KO16KSC5601;
Database altered.

7. Character Set 변경이 완료되었다. DB 를 shutdown 한다음 다시 startup 시킨다.

SQL> SHUTDOWN
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP
ORACLE instance started.

Total System Global Area  780140544 bytes
Fixed Size                  8797632 bytes
Variable Size             574620224 bytes
Database Buffers          192937984 bytes
Redo Buffers                3784704 bytes
Database mounted.
Database opened.