Oracle varchar2 Chinese characters

前端之家收集整理的这篇文章主要介绍了Oracle varchar2 Chinese characters前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


This doc describe how to insert a Chinese character into Oracle varchar2 datatype column


1. Check character set is correct in database

$ sqlplus scott/tiger@orcl

sql*Plus: Release 11.2.0.1.0 Production on Thu Dec 22 19:31:42 2016

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


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning,OLAP,Advanced Analytics and Real Application Testing options

sql> select * from V$NLS_PARAMETERS where PARAMETER in ('NLS_LANGUAGE','NLS_TERRITORY','NLS_CHARACTERSET');

PARAMETER
----------------------------------------------------------------
VALUE                                                                CON_ID
---------------------------------------------------------------- ----------
NLS_LANGUAGE
AMERICAN                                                                  0

NLS_TERRITORY
AMERICA                                                                   0

NLS_CHARACTERSET
AL32UTF8                                                                  0

sql> quit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning,Advanced Analytics and Real Application Testing options

2. Set NLS_LANG value,which is in the format [NLS_LANGUAGE]_[NLS_TERRITORY].[NLS_CHARACTERSET].
$ export NLS_LANG=AMERICAN_AMERICA.AL32UTF8


3. Insert data

$ sqlplus scott/tiger@orcl
sql> CREATE TABLE TESTTAB(A DECIMAL(2,0),C VARCHAR2(20));
Table created.

sql> INSERT INTO(A,C) TESTTAB VALUES(1,'你好');
1 row created.

sql> SELECT * FROM TESTTAB;

         A C
---------- --------------------
         1 你好


sql> SELECT RAWTOHEX(C) FROM TESTTAB;

RAWTOHEX(C)
----------------------------------------
E4BDA0E5A5BD


sql> INSERT INTO TESTTAB(A,C) VALUES(2,UTL_RAW.CAST_TO_VARCHAR2 (HEXTORAW('E4BDA0E5A5BD')));
1 row created.

sql> SELECT * FROM TESTTAB;

sql> SELECT * FROM TESTTAB;

         A C
---------- --------------------
         1 你好
         2 你好
原文链接:https://www.f2er.com/oracle/210689.html

猜你在找的Oracle相关文章