search
HomeDatabaseMysql TutorialOracle数据库多语言支持

可以从Session, Instance, Database三个级别来对NLS参数进行设置。Session级别的设置覆盖Instance级别的设置,Instance级别的设置

一、NLS Parameter

Oracle called globalization support National Language Support (NLS),

可以从Session, Instance, Database三个级别来对NLS参数进行设置。
Session级别的设置覆盖Instance级别的设置,Instance级别的设置覆盖Database级别的设置。
相应地,Oracle提供NLS_SESSION_PARAMETERS,NLS_INSTANCE_PARAMETERS,NLS_DATABASE_PARAMETERS这3个视图来查看NLS参数。
此外,还可以在SQL函数中指定NLS参数,这些函数称作locale-dependent。

A) NLS_SESSION_PARAMETERS
此视图中的参数可以通过"ALTER SESSION "语句来进行设置。
ALTER SESSION SET parameter_name=parameter_value [ parameter_name=parameter_value ]... ;
如果没有通过"ALTER SESSION "语句设置过,那么使用NLS_LANG环境变量的定义值。(NLS_LANG环境变量下面详细说明)
如果NLS_LANG也没有被定义,那么沿用NLS_INSTANCE_PARAMETERS中的设定值。
这些参数影响到客户端的错误信息显示语言;日期,数字,货币等的显示格式;排序结果等。

B) NLS_INSTANCE_PARAMETERS
此视图中中的参数设定是数据库启动时参照init.ora中的设定而来。 可以通过"ALTER SYSTEM"语句更改。
NLS_LANGUAGE设定决定了alert.log和trace files中的Server错误信息的语言。

C) NLS_DATABASE_PARAMETERS
此视图中的参数是创建数据库时决定的。数据库创建好以后不能改动,不要通过修改系统表格来修改设定。
如果INSTANCE和SESSION参数没有设定,那么默认使用这里的参数。
NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET 参数是创建数据库时决定的,不能被INSTANCE和SESSION参数覆盖,,不要在创建完数据库后试图修改它们,这种尝试会损坏数据库。(关于这2个参数下面有详细说明)

注1:NLS_DATABASE_PARAMETERS视图等价于SELECT name,value$ from sys.props$ where name like '%NLS%'。
注2:V$NLS_PARAMETERS视图给出了当前的SESSION参数以及NLS_DATABASE_PARAMETERS视图中的2个CHARACTERSET参数。
注3:select userenv ('language') from dual; select sys_context('userenv','language') from dual;这2个语句执行结果等同于
          _ .,
          这个结果貌似NLS_LANG,但是实际上不是,NLS_LANG定义的是客户端的字符集。
注4:select userenv ('lang') from dual; 返回的是Session参数NLS_LANGUAGE的简写。
注5:V$NLS_VALID_VALUES视图返回NLS_LANGUAGE, NLS_SORT, NLS_TERRITORY, NLS_CHARACTERSET的有效取值。

D) Locale-dependent SQL Function
SQL functions whose behavior depends on the values of NLS parameters are called locale-dependent.
依赖于NLS参数的SQL函数包括:
?TO_CHAR
?TO_DATE
?TO_NUMBER
?NLS_UPPER
?NLS_LOWER
?NLS_INITCAP
?NLSSORT
In all of the preceding functions, you can specify these NLS parameters:以上函数中可以指定的参数包括:
?NLS_DATE_FORMAT
?NLS_DATE_LANGUAGE
?NLS_NUMERIC_CHARACTERS
?NLS_CURRENCY
?NLS_ISO_CURRENCY
?NLS_DUAL_CURRENCY
?NLS_CALENDAR
?NLS_SORT
此外对于NLSSORT函数,还可以指定以下参数。
?NLS_LANGUAGE
?NLS_TERRITORY
按照'parameter=value' ['parameter=value']...的格式来指定参数。
例如,
select to_char(sysdate,'DD-MON-YYYY','NLS_DATE_LANGUAGE=''SIMPLIFIED CHINESE''') from dual;结果返回 "04-8月 -2011"
select * from employees order by nlssort(name,'NLS_SORT=SCHINESE_PINYIN_M');

E) NLS_LANG
NLS_LANG这个参数比较特殊,它是通过环境变量(UNIX)或者注册表(WINDOWS)定义的。它分三部分,格式如下:
    NLS_LANG = _.
部分设定了SESSION的NLS_LANGUAGE参数;
_部分设定了SESSION的NLS_TERRITORY参数;
.部分设定了CLIENT的字符集。它会影响到如何转换客户端的字符集到数据库字符集。
这三部分可以只定义任意一个/几个部分。
如果只有_部分,默认等于AMERICAN;
如果只有部分,_的值根据的值来决定;
如果既没有_部分也没有部分,这2部分认等于AMERICAN_AMERICA;
如果没有定义NLS_LANG,那么默认值_.US7ASCII,其中_部分根据NLS_INSTANCE_PARAMETERS中的值来决定。

NLS_LANG参数不能通过ALTER SESSION或者ALTER SYSTEM来更改(但是可以更改NLS_LANGUAGE和NLS_TERRITORY),也不能定义在init.ora中。
数据库创建的时候定义此参数也不影响数据库的设定,包括不会影响数据库的NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET 参数。
NLS_LANG参数的客户端字符集定义部分不能通过查询任何系统表格或视图得到。
(感觉实际上这个参数应该只会影响到客户端,也就是NLS_SESSION_PARAMETERS)

NLS_LANG直接设定了NLS_LANGUAGE和NLS_TERRITORY参数,还间接设定了其他的NLS参数。
NLS_DATE_LANGUAGE 和 NLS_SORT 根据NLS_LANGUAGE决定取值;
NLS_CURRENCY, NLS_DUAL_CURRENCY, NLS_ISO_CURRENCY, NLS_DATE_FORMAT, NLS_TIMESTAMP_FORMAT, NLS_TIMESTAMP_TZ_FORMAT, NLS_NUMERIC_CHARACTERS 根据NLS_TERRITORY决定取值。

注1:NLS_LANG在WINDOWS注册表中的位置:HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_xxx


NLS_INSTANCE_PARAMETERS shows the current NLS instance parameters that have been explicitly set and the values of the NLS instance parameters.
These are the settings in the init.ora of the database at the moment that the database was started or set through ALTER SYSTEM.
If the parameter is not explicitly set in the init.ora or defined by ALTER SYSTEM then its value is NOT derived from a "higher" parameter (we are talking about parameters like NLS_SORT that derive a default from NLS_LANGUAGE in NLS_SESSION_PARAMETERS, this is NOT the case for NLS_INSTANCE_PARAMETERS)
* NLS_LANG is not an init.ora parameter; NLS_LANGUAGE and NLS_TERRITORY are so you need to set NLS_LANGUAGE and NLS_TERRITORY separately.
* You cannot define the or NLS_LANG in the init.ora.The client characterset is defined by the NLS_LANG on the client OS (see above).
* You cannot define the database characterset in the init.ora. The database characterset is defined by the "Create Database" command.
* These settings take precedence above the NLS_DATABASE_PARAMETERS.
* These values are used for the NLS_SESSION_PARAMETERS if the client the NLS_LANG is NOT set.
* The NLS_LANGUAGE in the instance parameters also declares the language for the server error messages in alert.log and in trace files.

C) NLS_DATABASE_PARAMETERS
NLS_DATABASE_PARAMETERS shows the values of the NLS parameters for the database. The values are stored in the database.
Defaults to AMERICAN_AMERICA if there are no parameters explicitly set in the init.ora during database creation time. If there is parameters set in the init.ora during database creation you see them here. There is no way to change these after the database creation. Do NOT attempt to update system tables to bypass these settings! These settings are used to give the database a default if the INSTANCE and SESSION parameters are not set.
The database (national) character set NLS_(NCHAR)_CHARACTERSET) is defined by the "Create Database" command.
* The NLS_CHARACTERSET and NLS_NCHAR_CHARACTERSET parameters cannot be overridden by instance or session parameters.
They are defined by the value specified in the "CREATE DATABASE command and are not intended to be changed afterwards dynamically. Do NOT update system tables to change the character set. This can corrupt your database and potentially make it impossible to open the database again.
* Setting the NLS_LANG during the creation of the database does not influence the NLS_DATABASE_PARAMETERS.
* The NLS_LANG set during the database creation has NO impact on the database National Characterset.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

MySQL's Purpose: Storing and Managing Data EffectivelyMySQL's Purpose: Storing and Managing Data EffectivelyApr 16, 2025 am 12:16 AM

MySQL is an efficient relational database management system suitable for storing and managing data. Its advantages include high-performance queries, flexible transaction processing and rich data types. In practical applications, MySQL is often used in e-commerce platforms, social networks and content management systems, but attention should be paid to performance optimization, data security and scalability.

SQL and MySQL: Understanding the RelationshipSQL and MySQL: Understanding the RelationshipApr 16, 2025 am 12:14 AM

The relationship between SQL and MySQL is the relationship between standard languages ​​and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor