关于数据库:Oracle数据库字符集编码修改

36次阅读

共计 1878 个字符,预计需要花费 5 分钟才能阅读完成。

作者:threedayman

起源:恒生 LIGHT 云社区

背景

我的项目默认须要应用 ZHS16GBK,当应用 UTF8 进行编码时,会呈现插入数据超过字段长度限度问题。

起因:gbk 编码中文字符占用两个字节,utf8 编码中文字符时占用三个字节。

为了使初始化脚本可能失常运行,须要将数据库 UTF8 的编码改成 ZHS16GBK 编码

批改步骤

通过以下命令连贯到数据库

bash-4.2$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Thu Dec 9 19:17:39 2021
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

查看以后应用的字符编码

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

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

敞开数据库

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

启动

SQL> startup mount
ORACLE instance started.

Total System Global Area 2.0267E+10 bytes
Fixed Size                 12684864 bytes
Variable Size            3355443200 bytes
Database Buffers         1.6844E+10 bytes
Redo Buffers               54423552 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> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area 2.0267E+10 bytes
Fixed Size                 12684864 bytes
Variable Size            3355443200 bytes
Database Buffers         1.6844E+10 bytes
Redo Buffers               54423552 bytes
Database mounted.
Database opened.
SQL> select userenv('language') from dual;

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

通过查看以后字符集曾经批改为 ZHS16GBK。

注:生产环境字符集不要随便进行批改,免得造成不可挽回的损失。


想向技术大佬们多多取经?开发中遇到的问题何处探讨?如何获取金融科技海量资源?

恒生 LIGHT 云社区,由恒生电子搭建的金融科技业余社区平台,分享实用技术干货、资源数据、金融科技行业趋势,拥抱所有金融开发者。

扫描下方小程序二维码,退出咱们!

正文完
 0