Search code examples
oracle-databasesqlplus

Oracle sqlplus Chinese characters garbled


  1. I run a simple query with oracle database 11g on CentOS, but I got wrong CHARACTER SET.
SQL> select col_name from table_name where rownum <= 1;

col_name 
--------------------------------------------------------------------------------
¸ñ귎Ϊʯҩ¼¯΅mRNAт¹ےࠃ萮Ŀ802³µ¼乄լ¾»»¯ůͨ¹¤³̡£
  1. I get database CHARACTER SET as follows
SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK
  1. Set CHARACTER SET to client
    echo 'export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"'>>/etc/profile && source /etc/profile
  2. rerun query SQL, but also got problem, How can I resolve it.

Solution

  • Check your terminal settings with locale charmap or echo $LANG and verify if it matches with ZHS16GBK.

    It is not required to use the same character set as your database. Using NLS_LANG=AMERICAN_AMERICA.AL32UTF8 and UTF-8 in your terminal will also work. It is important that NLS_LANG matches your terminal character set.

    See also OdbcConnection returning Chinese Characters as "?"