【不错】浅析Oracle三层全球化支持(NLS)
作为一个成熟的商业 数据库 软件 , Oracle 对全球化( Global Support )有着全面的支持和解决方案。 Oracle 在国际化支持方面主要体现在几个方面: ü 全球化字符集支持;目前, Oracle 支持所有主流的字符集样式。通过 NLS_CHARACTER 和 NLS_NCHAR_CHARACT
作为一个成熟的商业数据库软件,Oracle对全球化(Global Support)有着全面的支持和解决方案。Oracle在国际化支持方面主要体现在几个方面:
ü
ü
ü
ü
NLS是一套覆盖面广、内容庞杂的知识体系。笔者计划在接下来用一个系列来分析这个体系。本次,我们只是给NLS一个简单的体系介绍:Oracle的三层NLS体系关系和优先级配置。
1、环境介绍
笔者选择Oracle 11gR2进行试验。
SQL> select * from v$version;
BANNER
---------------------------------------
Oracle
PL/SQL Release 11.2.0.1.0 - Production
CORE
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 – Production
服务器是Red Hat 5.3 32bit,安装时选择的是英文,美语。
[oracle@bspdev ~]$ uname -a
Linux bspdev.localdomain 2.6.18-308.el5 #1 SMP Tue Feb 21 20:05:41EST 2012 i686 i686 i386 GNU/Linux
查看Linux系统支持语言和时区:
[oracle@bspdev ~]$ cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
[oracle@bspdev sysconfig]$ pwd
/etc/sysconfig
[oracle@bspdev sysconfig]$ cat clock
# The ZONE
# The timezone of the system is defined by the contents of/etc/localtime.
ZONE="Asia/Shanghai"
UTC=true
ARC=false
客户端使用的是中文的Windows
NLS_LANG参数告知本地所在地中国、中文语言和ZHS16GBK字符集。
2、三层NLS体系
Oracle的Global Support复杂的原因之一,就是Oracle的三层NLS体系。任何一个会话session在连接入数据库之后,都会面对三层NLS参数体系,分别为:Database、Instance和Session。
ü
ü
ü
下面我们分别来介绍几个层面参数中的重要内容。
3、Database Level NLS Parameter
Database level参数是三层体系中最底层,这个层面的参数取值和Oracle数据库创建时的配置选项密切相关。我们在联入数据库时,可以通过几个视图来查看这个“根本性”的参数内容。
SQL> select * from nls_database_parameters;
PARAMETER
---------------------------------------------------------------------
NLS_LANGUAGE
NLS_TERRITORY
NLS_CURRENCY
NLS_ISO_CURRENCY
NLS_NUMERIC_CHARACTERS
NLS_CHARACTERSET
NLS_CALENDAR
NLS_DATE_FORMAT
NLS_DATE_LANGUAGE
NLS_SORT
NLS_TIME_FORMAT
NLS_TIMESTAMP_FORMAT
NLS_TIME_TZ_FORMAT
NLS_TIMESTAMP_TZ_FORMAT
NLS_DUAL_CURRENCY
NLS_COMP
NLS_LENGTH_SEMANTICS
NLS_NCHAR_CONV_EXCP
NLS_NCHAR_CHARACTERSET
NLS_RDBMS_VERSION
20 rows selected
nls_xxx_parameters系列视图非常重要,特别是在我们配置NLS参数的过程中。我们可以通过nls_database_parameters查看到Database的NLS参数。
NLS_CHARACTERSET和NLS_NCHAR_CHARACTERSET用于表示Oracle在保存varchar2/char和nvarchar2/nchar字段时的保存类型。从Oracle官方推荐的角度,我们设置AL32UTF8字符集作为数据库字符集,基本上就可以应对常见的字符文字类型了。
在安装程序OUI运行是,AL32UTF8往往不是默认选项。Oracle OUI程序会根据所在服务器操作系统的配置内容,为我们选择出一个字符集。
在从操作系统选择出字符集合的过程中,NLS_LANG(LANG)环境变量起到很重要的作用。NLS_LANG是我们安装Oracle过程中,确定NLS参数的一个重要环境变量。
根据Oracle的要求,NLS_LANG中包括了Oracle所在地域Territory、语言Language和字符集CharacterSet三部分内容。
NLS_LANG=_.
如果我们需要在配置Oracle前就确定这些参数内容,可以预先定义环境变量NLS_LANG。Unix/Linux环境下,可以配置在Oracle用户的.bash_profile中。而Windows环境下,这个参数要配置在注册表中。
此外,NLS_DATA_LANGUAGE用来表示Oracle在显示日期类型的文字内容时,使用什么语言。
Database Level NLS parameter是非常基本的,起作用的范围主要数据库内部。另一方面,Database Level NLS Parameter是作为Instance Level配置的默认基础值。在安装数据库后,我们基本不能、也不会对database level的NLS参数进行修改。我们的“手脚”只能在Instance和Session level进行。
3、Instance level NLS Parameter
Instance Level NLS parameter,就是我们可以控制的领域了。Instance参数主要来自于参数文件SPFILE/PFILE。我们可以通过nls_instance_parameters来查看这个层面的参数配置。
SQL> select * from nls_instance_parameters;
PARAMETER
------------------------------ -------------------------
NLS_LANGUAGE
NLS_TERRITORY
NLS_SORT
NLS_DATE_LANGUAGE
NLS_DATE_FORMAT
NLS_CURRENCY
NLS_NUMERIC_CHARACTERS
NLS_ISO_CURRENCY
NLS_CALENDAR
NLS_TIME_FORMAT
NLS_TIMESTAMP_FORMAT
NLS_TIME_TZ_FORMAT
NLS_TIMESTAMP_TZ_FORMAT
NLS_DUAL_CURRENCY
NLS_COMP
NLS_LENGTH_SEMANTICS
NLS_NCHAR_CONV_EXCP
17 rows selected
相对于database level,Instance level的参数数量是很少的。通常我们不会在参数文件层面进行NLS参数配置,保持Database Level的默认配置就可以了。
这样的原因是Instance Level配置是针对所有连接而言的。而国际化的目的就是在于不同连接用户,看到Local化的结果。无论Instance Level进行何种的配置,最终很有可能都是被Session level的所覆盖。
Database level之所以会有完备的NLS参数,很大层面上是提供了一个基础参数集合和存储标准。NLS的重头在session层面。
4、Session Level NLS Parameter
Session Level的NLS参数是和用户最直接交互的部分。我们可以通过nls_session_parameters视图查看到这个内容。
SQL> select * from nls_session_parameters;
PARAMETER
------------------------------ -------------------------
NLS_LANGUAGE
NLS_TERRITORY
NLS_CURRENCY
NLS_ISO_CURRENCY
NLS_NUMERIC_CHARACTERS
NLS_CALENDAR
NLS_DATE_FORMAT
NLS_DATE_LANGUAGE
NLS_SORT
NLS_TIME_FORMAT
NLS_TIMESTAMP_FORMAT
NLS_TIME_TZ_FORMAT
NLS_TIMESTAMP_TZ_FORMAT
NLS_DUAL_CURRENCY
NLS_COMP
NLS_LENGTH_SEMANTICS
NLS_NCHAR_CONV_EXCP
17 rows selected
session level的参数是影响最终我们看到NLS结果的控制因素。Session level的NLS参数来自客户端配置。对Windows而言,就是我们注册表中关于NLS_LANG等一系列的环境变量。对Unix/Linux而言,就是我们配置在.bash_profile文件中定义的相应内容。
注意,NLS_LANG本身包括的内容很多。NLS_LANG包括了客户端地域、语言和字符集信息。地域间接影响到时区,语言会影响到显示语言。而字符集更是影响数据从服务器传递过来客户端后,进行的转换策略。
在三层NLS体系下,Session Level的Parameter起到最后的决定作用。如果Session level没有配置,Oracle会选择Instance乃至Database的配置。Session Level的配置会覆盖Instance level的取值。
我们可以根据自己的情况,动态的进行调节session level nls parameter。如果我们只是希望NLS暂时性修改,可以选择alter session set语句进行参数切换。
SQL> select sysdate from dual;
SYSDATE
--------------
17-9月 -12
SQL> alter session set nls_date_format='yyyy-mm-ddhh24:mi:ss';
会话已更改。
SQL> select sysdate from dual;
SYSDATE
-------------------
2012-09-17 06:23:58
如果希望长期的修改,可以考虑在环境变量的层面上修改参数。在windows上,可以添加注册表参数。
SQL> select * from nls_session_parameters whereparameter='NLS_DATE_FORMAT';
PARAMETER
------------------------------ -------------------------
NLS_DATE_FORMAT
SQL> conn sys/oracle@wilson as sysdba
已连接。
SQL> select sysdate from dual;
SYSDATE
-------------------
2012-09-17 06:29:02
5、结论
NLS参数对我们开发和使用Oracle,至关重要!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

Creating an Oracle table involves the following steps: Use the CREATE TABLE syntax to specify table names, column names, data types, constraints, and default values. The table name should be concise and descriptive, and should not exceed 30 characters. The column name should be descriptive, and the data type specifies the data type stored in the column. The NOT NULL constraint ensures that null values are not allowed in the column, and the DEFAULT clause specifies the default values for the column. PRIMARY KEY Constraints to identify the unique record of the table. FOREIGN KEY constraint specifies that the column in the table refers to the primary key in another table. See the creation of the sample table students, which contains primary keys, unique constraints, and default values.

Data import method: 1. Use the SQLLoader utility: prepare data files, create control files, and run SQLLoader; 2. Use the IMP/EXP tool: export data, import data. Tip: 1. Recommended SQL*Loader for big data sets; 2. The target table should exist and the column definition matches; 3. After importing, data integrity needs to be verified.

Oracle View Encryption allows you to encrypt data in the view, thereby enhancing the security of sensitive information. The steps include: 1) creating the master encryption key (MEk); 2) creating an encrypted view, specifying the view and MEk to be encrypted; 3) authorizing users to access the encrypted view. How encrypted views work: When a user querys for an encrypted view, Oracle uses MEk to decrypt data, ensuring that only authorized users can access readable data.

There are three ways to view instance names in Oracle: use the "sqlplus" and "select instance_name from v$instance;" commands on the command line. Use the "show instance_name;" command in SQL*Plus. Check environment variables (ORACLE_SID on Linux) through the operating system's Task Manager, Oracle Enterprise Manager, or through the operating system.

Uninstall method for Oracle installation failure: Close Oracle service, delete Oracle program files and registry keys, uninstall Oracle environment variables, and restart the computer. If the uninstall fails, you can uninstall manually using the Oracle Universal Uninstall Tool.

There are the following methods to get time in Oracle: CURRENT_TIMESTAMP: Returns the current system time, accurate to seconds. SYSTIMESTAMP: More accurate than CURRENT_TIMESTAMP, to nanoseconds. SYSDATE: Returns the current system date, excluding the time part. TO_CHAR(SYSDATE, 'YYY-MM-DD HH24:MI:SS'): Converts the current system date and time to a specific format. EXTRACT: Extracts a specific part from a time value, such as a year, month, or hour.

An AWR report is a report that displays database performance and activity snapshots. The interpretation steps include: identifying the date and time of the activity snapshot. View an overview of activities and resource consumption. Analyze session activities to find session types, resource consumption, and waiting events. Find potential performance bottlenecks such as slow SQL statements, resource contention, and I/O issues. View waiting events, identify and resolve them for performance. Analyze latch and memory usage patterns to identify memory issues that are causing performance issues.
