Chapter20-Using Globalization Support

Oracle supports different classes of character encoding schemes:

  • Single-byte character sets
    • 7-bit
    • 8-bit
  • Varying-width multibyte character sets
  • Fixed-width multibyte character sets
  • Unicode(AL32UTF8,AL16UTF16,UTF8)
  • 查看数据库中的字符集信息

    • select * from nls_database_parameters;
      • NLS_CHARACTERSET        AL32UTF8(主字符集)  
      • NLS_NCHAR_CHARACTERSET           AL16UTF16(辅助字符集)
  • Guideline for Character Sets
    • Considerations:
      • What languages must be the database support?
      • What are interoperability concerns with system resources and applications?
      • What are the performance implications?
      • What are the restrictions?
  • 在安装数据库时,选择字符集的原则:服务器端Oracle字符集是客户端字符集的超集;[UCS-2]->[UTF-16]->[UTF-8]
    • UTF-8 is the 8-bit encoding of Unicode.It is a variable-width encoding and a strict superset of ASCII.意味着如果你的数据库中主字符集编码是7-bit的,在转换到UTF-8的字符集的时候,是完全没有问题的,因为UTF-8是ASCII 7-bit字符集的严格超集
  • ALTER SESSION SET NLS_LANGUAGE=Italian;更改会话语言命令;Oracle会根据不同的会话语言,显示不同的数据格式,比如日期数据;
      • Lang-Dependent Behavior
      • Table3-1 Methods of Setting NLS Parameters and Their Priorities

      

      • Priority     Method
        1(highest) Explicitly set in SQL functions
        2 Set by an ALTER SESSION statement
        3 Set as an environment variable
        4 Specified in the initalization parameter file
        5 Default

 

 

  

      ALTER SESSION SET NLS=Italian

    • 查询登陆SESSION的NLS信息
      • SELECT * FROM NLS_SESSION_PARAMETERS;
  • NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK 这个参数设定了,下面的货币符号、日期格式、排序方式等等规则就确定了(如下);注意NLS_LANG只能在环境变量中设置,不可以在SESSION或SPFILE中设置;
    • NLS_DATE_FORMAT
    • NLS_DATE_LANGUAGE
    • NLS_SORT
    • NLS_NUMERIC_CHARACTERS
    • NLS_CURRENCY
    • NLS_ISO_CURRENCY
    • NLS_CALENDAR
  • Getting NLS Settings Information
    • NLS_DATABASE_PARAMETERS
    • NLS_INSTANCE_PARAMETERS 参数数据受SPFILE中的设置影响;
    • NLS_SESSION_PARAMETERS 参数数据受客户端的环境变量影响;
    • V$NLS_VALID_VALUES    
      • LANGUAGE SORT TERRITORY CHARACTERSET
    • V$NLS_PARAMETERS
      • NLS SESSION PARAMETERS,NLS_CHARACTERSET    
  • DEMO
    • NLS_SORT参数使用;如下查询结果,分析原因,可根据SELECT * FROM NLS_DATABASE_PARAMETERS;中的NLS_SORT参数值来判断;
      • 建表
        • CREATE TABLE H
          (
          ID NUMBER,
          NAME VARCHAR2(10)
          );

      • 插入数据
        • INSERT INTO H VALUES(1,'一');
          INSERT INTO H VALUES(2,'二');
          INSERT INTO H VALUES(3,'三');
          INSERT INTO H VALUES(4,'四');
          INSERT INTO H VALUES(5,'五');
          INSERT INTO H VALUES(6,'六');
          INSERT INTO H VALUES(7,'七');
          INSERT INTO H VALUES(8,'八');
          INSERT INTO H VALUES(9,'九');
          INSERT INTO H VALUES(10,'十');

          COMMIT;
        • 执行查询SELECT * FROM H;排序一切正常;
        • 执行查询SELECT * FROM H ORDER BY NAME;排序乱七八糟;
posted @ 2013-03-11 18:49  ArcerZhang  阅读(184)  评论(0编辑  收藏  举报