Oracle字符集AL32UTF8 改ZHS16GBK字符集

时间:2022-07-19 08:30:14

数据导入数据突然发现大量报错,字段长度不够

ORA-02374: conversion error loading table "ECM"."C_CAR_CARD"
ORA-12899: value too large for column CARD_MANUFACTURER (actual: 48, maximum: 32)

ORA-02372: data for row: CARD_MANUFACTURER : 0X'BBB9B9FEB9FEB9FEB9FEB9FEB9FEB9FEB9FEB9FEB9FEB9FEB9'
 

一看肯定字符长度不一致

验证两个库之间的字符

查看两边字符集

oracle server 端 字符集查询 

select userenv('language') from dual 

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK

目标端字符集默认AL32UTF8

特别对于汉子存放1个汉子存放占用长度不一致

 

数据已经导入小半,进行目标端删除操作

drop user username cascade;---递归删除

重新建立用户

create user 

grant xxx to

修改字符集

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area  236000356 bytes

Fixed Size                   451684 bytes

Variable Size             201326592 bytes

Database Buffers           33554432 bytes

Redo Buffers                 667648 bytes

Database mounted.

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;

System altered.

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.

SQL> ALTER DATABASE CHARACTER SET ZHS16GBK;

ALTER DATABASE CHARACTER SET ZHS16GBK

*

ERROR at line 1:

ORA-12712: new character set must be a superset of old character set

提示:新字符集必须为旧字符集的超集,这时可以跳过超集的检查做更改:

SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;

Database altered.

SQL> select * from v$nls_parameters;

检查是否更改完成:

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup

ORACLE instance started.

Total System Global Area  236000356 bytes

Fixed Size                   451684 bytes

Variable Size             201326592 bytes

Database Buffers           33554432 bytes

Redo Buffers                 667648 bytes

Database mounted.

Database opened.

SQL> select * from v$nls_parameters;

 

设置oracle用户的的环境

export NLS_LANG=“SIMPLIFIED Chinese_CHINA.ZHS16GBK”
############################################################################
stty erase ^H
export TMP=/tmp
export TMPDIR=$TMP


export NLS_LANG="SIMPLIFIED Chinese_CHINA.ZHS16GBK"

 

重新导入数据没有报错