les_20_g11n
TRANSCRIPT
-
8/10/2019 les_20_g11n
1/30
Copyright 2008, Oracle. All rights reserved.
Globalization
-
8/10/2019 les_20_g11n
2/30
Copyright 2008, Oracle. All rights reserved.20 - 2
Objectives
After completing this lesson, you should be able to: Determine a correct database character set that meets your
business requirements
Obtain globalization support configuration information
Customize language-dependent behavior for the databaseand individual sessions
Specify different linguistic sorts for queries
Retrieve data that matches a search string ignoring case or
accent differences
-
8/10/2019 les_20_g11n
3/30
Copyright 2008, Oracle. All rights reserved.20 - 3
Globalization Support Features
Language support Territory support
Character set support
Linguistic sorting
Message support Date and time formats
Numeric formats
Monetary formats
French
data
Japanese
data
-
8/10/2019 les_20_g11n
4/30
Copyright 2008, Oracle. All rights reserved.20 - 4
What Every DBA Needs to Know
What is a character set? How are character sets used?
Problems to avoid
Choosing your character set
Obtaining character set information Specifying language-dependent behavior
Using linguistic searching and sorting
Using data conversion
-
8/10/2019 les_20_g11n
5/30
Copyright 2008, Oracle. All rights reserved.20 - 5
What Is a Character Set?
The Oracle database supports different classes of character-encoding schemes:
Single-byte character sets
7-bit
8-bit Multibyte character sets, including Unicode
-
8/10/2019 les_20_g11n
6/30
Copyright 2008, Oracle. All rights reserved.20 - 7
Understanding Unicode
Supplementarycharacters
AL32UTF8 AL16UTF16
63
EE AA 9E
F0 9D 84 9E
64
C3D0 A4
B6
t
d
0063
00E1
0074
A89E
D834 DD1E
0064
00F60424
c
C3
74
91
Encoding: Representing characters with byte sequences
-
8/10/2019 les_20_g11n
7/30Copyright 2008, Oracle. All rights reserved.20 - 9
How Are Character Sets Used?
Oracle Net compares the client NLS_LANGsetting to thecharacter set on the server.
If needed, conversion occurs automatically and
transparently.
Client
Oracle Net
NLS_LANG
Server
-
8/10/2019 les_20_g11n
8/30Copyright 2008, Oracle. All rights reserved.20 - 10
Problems to Avoid
Example:
No conversion occurs, because it does not seem to berequired.
Issue: Invalid data are entered into the database.
Server
Database character set:
AL32UTF8
Client
Windows English
Code page: WE8MSWIN1252
NLS_LANG:
AL32UTF8 Oracle Net
-
8/10/2019 les_20_g11n
9/30Copyright 2008, Oracle. All rights reserved.20 - 11
CREATE DATABASE ...CHARACTER SET US7ASCIINATIONAL CHARACTER SETUTF8 ...
% export NLS_LANG=SIMPLIFIED
CHINESE_HONG KONG.ZHS16GBK
Another Sample Problem
-
8/10/2019 les_20_g11n
10/30Copyright 2008, Oracle. All rights reserved.20 - 12
Choosing Your Character Set
Trade-offs to consider Choosing the correct character set that meets your business
requirements now and in the future
Specifying the character set
Changing the character set after database creation
-
8/10/2019 les_20_g11n
11/30Copyright 2008, Oracle. All rights reserved.20 - 13
Database Character Sets and
National Character Sets
Database Character Sets National Character Sets
Defined at creation time Defined at creation time
Cannot be changed without
re-creation (exceptions in certainconfigurations)
Can be exchanged
Store data columns of type CHAR,VARCHAR2, CLOB, LONG
Store data columns of typeNCHAR, NVARCHAR2, NCLOB
Can store varying-width character
sets
Can store Unicode using either
AL16UTF16or
UTF8
-
8/10/2019 les_20_g11n
12/30Copyright 2008, Oracle. All rights reserved.20 - 14
Obtaining Character Set Information
SQL> SELECT parameter, value2 FROM nls_database_parameters
3 WHERE parameter LIKE '%CHARACTERSET%';
PARAMETER VALUE----------------------- -------------NLS_CHARACTERSET WE8ISO8859P1NLS_NCHAR_CHARACTERSET AL16UTF16
2 rows selected.
-
8/10/2019 les_20_g11n
13/30Copyright 2008, Oracle. All rights reserved.20 - 15
SELECT sysdate FROM dual;
Initialization parameters for the database server
Environment variables for the clients
ALTER SESSIONcommand
Specifying Language-Dependent Behavior
SQL function
-
8/10/2019 les_20_g11n
14/30Copyright 2008, Oracle. All rights reserved.20 - 16
Specifying Language-Dependent
Behavior for the Session
Specify the locale behavior with the NLS_LANGenvironmentvariable:
Language
Territory
Character set
Set other NLS environment variables to:
Override database initialization parameter settings for all
sessions
Customize the locale behavior
Change the default location of the NLS library files
NLS_LANG=FRENCH_CANADA.WE8ISO8859P1
-
8/10/2019 les_20_g11n
15/30Copyright 2008, Oracle. All rights reserved.20 - 17
Language-Dependent and Territory-Dependent
Parameters
Parameter Default Values
NLS_LANGUAGE
NLS_DATE_LANGUAGE
NLS_SORT
AMERICAN
AMERICAN
BINARY
NLS_TERRITORY
NLS_CURRENCY
NLS_DUAL_CURRENCY
NLS_ISO_CURRENCY
NLS_DATE_FORMAT
NLS_NUMERIC_CHARACTERS
NLS_TIMESTAMP_FORMATNLS_TIMESTAMP_TZ_FORMAT
AMERICA
$
$
AMERICA
DD-MON-RR
.,
DD-MON-RRHH.MI.SSXFF AMDD-MON-RRHH.MI.SSXFF AM TZR
-
8/10/2019 les_20_g11n
16/30Copyright 2008, Oracle. All rights reserved.20 - 19
ALTER SESSION SET NLS_DATE_FORMAT='DD.MM.YYYY';
DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT',
'''DD.MM.YYYY''') ;
Specifying Language-Dependent Behavior
Using NLS parameters in SQL functions:
SELECT TO_CHAR(hire_date,'DD.Mon.YYYY','NLS_DATE_LANGUAGE=FRENCH')FROM employees
WHERE hire_date > '01-JAN-2000';
-
8/10/2019 les_20_g11n
17/30Copyright 2008, Oracle. All rights reserved.20 - 20
Linguistic Searching and Sorting
Sort order can be affected by: Case-sensitivity
Diacritics or accent characters
Combination of characters that is treated as a single
character Phonetics or character appearance
Cultural preferences
-
8/10/2019 les_20_g11n
18/30Copyright 2008, Oracle. All rights reserved.20 - 21
Linguistic Searching and Sorting
Three types of sorting: Binary sorting
Sorted according to the binary values of the encoded
characters
Monolingual linguistic sorting A two-pass sort based on a characters assigned major and
minor values
Multilingual linguistic sorting
Based on the ISO standard (ISO 14651), and the Unicode 3.2
Standard for multilingual collation Ordered by the number of strokes, PinYin, or radicals for
Chinese characters
-
8/10/2019 les_20_g11n
19/30Copyright 2008, Oracle. All rights reserved.20 - 22
Using Linguistic Searching and Sorting
You can specify the type of sort used for character data withthe:
NLS_SORTparameter
Default value derived from the NLS_LANGenvironment
variable, if set
Can be specified for the session, client, or server
NLSSORTfunction
Defines the sorting method at the query level
-
8/10/2019 les_20_g11n
20/30Copyright 2008, Oracle. All rights reserved.20 - 24
Case-Insensitive and Accent-Insensitive
Search and Sort
Specify the linguistic name:
Examples:
Specify the sort action for WHEREclauses and PL/SQL
blocks:
Useful for migrated databases
NLS_SORT = [_AI | _CI]
NLS_SORT = FRENCH_M_AI
NLS_SORT = XGERMAN_CI
NLS_COMP = BINARY | ANSI
-
8/10/2019 les_20_g11n
21/30Copyright 2008, Oracle. All rights reserved.20 - 25
Support in SQL and Functions
The following SQL clauses support NLS_SORTandNLS_COMPsettings:
WHERE
ORDER BY
START WITH
HAVING
IN/NOT IN
BETWEEN
CASE-WHEN
The NLSSORT()function supports the case-insensitive andaccent-insensitive functionality.
-
8/10/2019 les_20_g11n
22/30Copyright 2008, Oracle. All rights reserved.20 - 26
Linguistic Index Support
Create an index on linguistically sorted values. Rapidly query data without having to specify ORDER BY
clause and NLSSORT:
Set the NLS_SORTparameter to match the linguistic
definition that you want to use for the linguistic sort when
creating the index.
CREATE INDEX list_word ON
list (NLSSORT(word, 'NLS_SORT=French_M'));
SELECT word FROM list;
-
8/10/2019 les_20_g11n
23/30Copyright 2008, Oracle. All rights reserved.20 - 27
Customizing Linguistic
Searching and Sorting
You can customize linguistic sorting for: Ignorable characters
Contracting or expanding characters
Special combination letters or special letters
Expanding characters or special letters Special uppercase and lowercase letters
Context-sensitive characters
Reverse secondary sorting
Canonical equivalence
-
8/10/2019 les_20_g11n
24/30Copyright 2008, Oracle. All rights reserved.20 - 29
Implicit ConversionBetween CLOBandNCLOB
Transparent implicit conversion is supported in: SQL INand OUTbind variables for query and DML
PL/SQL functions and procedure parameter passing
PL/SQL variable assignment
-
8/10/2019 les_20_g11n
25/30
Copyright 2008, Oracle. All rights reserved.20 - 30
NLS Data Conversion with Oracle Utilities
Multiple data conversions can take place when data isexported from one database and imported into another if the
same character sets are not used.
External tables use the NLS settings on the server for
determining the data character set.
SQL*Loader:
Conventional path: Data is converted into the sessioncharacter set specified by NLS_LANG.
Direct path: Data is converted using client-side directives.
-
8/10/2019 les_20_g11n
26/30
Copyright 2008, Oracle. All rights reserved.20 - 32
NLS Data Conversion with Data Pump
Data Pump Export always saves data in the same characterset as the database from which the data originates.
Data Pump Import converts the data to the character set of
the target database, if needed.
The Data Pump log file is written in the language specifiedby NLS_LANGfor the session that started Data Pump.
-
8/10/2019 les_20_g11n
27/30
Copyright 2008, Oracle. All rights reserved.20 - 33
Language and Character Set File Scanner(LCSSCAN)
Character set
-
8/10/2019 les_20_g11n
28/30
Copyright 2008, Oracle. All rights reserved.20 - 34
Setting the Database Time Zone
The current time zone in the database is determined by thefollowing:
The SET TIME_ZONEclause of the CREATE DATABASE
statement
The time zone of the operating system on the databaseserver host
The time zone specified by the ALTER SESSION SETTIME_ZONEcommand
CREATE DATABASE ... SET TIME_ZONE='-04:00';
-
8/10/2019 les_20_g11n
29/30
Copyright 2008, Oracle. All rights reserved.20 - 35
Summary
In this lesson, you should have learned how to: Determine a correct database character set that meets your
business requirements
Obtain globalization support configuration information
Customize language-dependent behavior for the databaseand individual sessions
Specify different linguistic sorts for queries
Retrieve data that matches a search string ignoring case or
accent differences
-
8/10/2019 les_20_g11n
30/30
Practice 20 Overview:
Using Globalization Support
This practice covers the following topics: Determining the database character set
Setting the NLS_SORTvariable