2 copyright © 2004, oracle. all rights reserved. using globalization support

Post on 21-Jan-2016

227 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

2Copyright © 2004, Oracle. All rights reserved.

Using Globalization Support

2-2 Copyright © 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to:

• Customize language-dependent behavior for the database and individual sessions

• Specify different linguistic sorts for queries

• Retrieve data that matches a search string ignoring case or accent differences

• Obtain Globalization support configuration information

2-3 Copyright © 2004, Oracle. All rights reserved.

Globalization Support Features

• Language support

• Territory support

• Character set support

• Linguistic sorting

• Message support

• Date and time formats

• Numeric formats

• Monetary formats

2-4 Copyright © 2004, Oracle. All rights reserved.

Encoding Schemes

Oracle Database supports different classes of character encoding schemes:

• Single-byte character sets– 7-bit– 8-bit

• Fixed-width multibyte character sets

• Varying-width multibyte character sets

• Universal character sets, such as Unicode

2-7 Copyright © 2004, Oracle. All rights reserved.

Database Character Sets and National Character Sets

Can store Unicode using either AL16UTF16 or UTF8

Can store varying-width character sets

Store data columns of type NCHAR, NVARCHAR2, NCLOB

Store data columns of type CHAR, VARCHAR2, CLOB, LONG

Can be exchangedCannot be changed without re-creation, few exceptions

Defined at creation timeDefined at creation time

National Character SetsDatabase Character Sets

2-9 Copyright © 2004, Oracle. All rights reserved.

Datetimes with Timezones

TIMESTAMP '2004-01-31 09:26:56.66 +02:00'

Valid value in V$TIMEZONE_NAMESTIMEZONE_REGION

00 to 59TIMEZONE_MINUTE

-12 to 14TIMEZONE_HOUR

00 to 59.9 (N) -- N indicates precisionSECOND

00 to 59MINUTE

00 to 23HOUR

01 to 31DAY

01 to 12MONTH

-4712 to 9999 (excluding 0)YEAR

Valid ValuesDatetime Field

2-10 Copyright © 2004, Oracle. All rights reserved.

Configuring the Database Local Timezone

• At the session level:

• Using an environment variable:

• At the database level:

ALTER SESSION SET time_zone = 'Europe/London';

ALTER SESSION SET time_zone = LOCAL;

$ export ORA_SDTZ = 'DB_TZ'

CREATE DATABASE ...

SET TIME_ZONE='UTC' ...

ALTER DATABASE SET TIME_ZONE='-01:00';

2-11 Copyright © 2004, Oracle. All rights reserved.

Configuring Datetime Formats

• NLS_TIMESTAMP_FORMAT• NLS_TIMESTAMP_TZ_FORMAT

Timezone Daylight savings timeTZD

Timezone region nameTZR

Timezone minutesTZM

Timezone hourTZH

Fractional secondsFF

DefinitionFormat Element

ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT =

'YYYY-MM-DD HH:MI:SS.FF TZR TZD';

2-12 Copyright © 2004, Oracle. All rights reserved.

Using Timezones

01-31-04 09:30:00.00 -05:00

01-31-04 09:30:00.00 America/New_York

01-31-04 13:30:00.00 -01:00

CREATE TABLE orders ( ...orderdate2 TIMESTAMP(3) WITH TIME ZONE ...);

INSERT INTO orders VALUES (...,'28-OCT-04 11:24:54.000 PM America/New_York', ...);

2-13 Copyright © 2004, Oracle. All rights reserved.

SELECT sysdate FROM dual;

Initialization parameter

Environment variable

ALTER SESSION command

Specifying Language-Dependent Behavior

SQL function

2-14 Copyright © 2004, Oracle. All rights reserved.

Specifying Language-Dependent Behavior for the Server

• NLS_LANGUAGE specifies:– The language for database messages– Day and month names– Symbols for A.D., B.C., a.m., p.m.– The default sorting mechanism– Affirmative and negative response strings

• NLS_TERRITORY specifies:– Day and week numbering– Credit and debit symbols– Default date format, decimal character,

group separator, list separator and the default ISO, dual and local currency symbols

2-15 Copyright © 2004, Oracle. All rights reserved.

Language and Territory Dependent Parameters

Parameter

NLS_LANGUAGE NLS_DATE_LANGUAGE NLS_SORT

Default Values

AMERICAN AMERICAN BINARY

AMERICA $ $ AMERICA DD-MON-RR ., DD-MON-RRHH.MI.SSXFF AM DD-MON-RRHH.MI.SSXFF AM TZR

NLS_TERRITORY NLS_CURRENCY NLS_DUAL_CURRENCY NLS_ISO_CURRENCY NLS_DATE_FORMAT NLS_NUMERIC_CHARACTERS NLS_TIMESTAMP_FORMAT NLS_TIMESTAMP_TZ_FORMAT

2-17 Copyright © 2004, Oracle. All rights reserved.

Other NLS Server Parameters

Parameter Default Value

NLS_CALENDAR Gregorian

NLS_COMP BINARY

NLS_LENGTH_SEMANTICS BYTE

NLS_NCHAR_CONV_EXCP FALSE

2-18 Copyright © 2004, Oracle. All rights reserved.

Specifying Language-Dependent Behavior for the Session

• Specify the locale behavior with the NLS_LANG environment variable:– 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

2-20 Copyright © 2004, Oracle. All rights reserved.

ALTER SESSION SET NLS_DATE_FORMAT='DD.MM.YYYY';

DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','''DD.MM.YYYY''') ;

Specifying Language-Dependent Behavior for the Session

2-21 Copyright © 2004, Oracle. All rights reserved.

Locale Variants

Belgium

Bonjour guten MorgenGoede ochtend

2-22 Copyright © 2004, Oracle. All rights reserved.

SELECT TO_CHAR(hire_date,'DD.Mon.YYYY', 'NLS_DATE_LANGUAGE=FRENCH') FROM employeesWHERE hire_date > '01-JAN-2000';

SELECT last_name, first_name, TO_CHAR(salary,'99G999D99', 'NLS_NUMERIC_CHARACTERS='',.''') FROM employees;

Using NLS Parameters in SQL Functions

2-24 Copyright © 2004, Oracle. All rights reserved.

Using NLS Parameters in SQL Functions

Function

TO_DATE

NLS Parameter

NLS_DATE_LANGUAGENLS_CALENDAR

NLS_DATE_LANGUAGENLS_NUMERIC_CHARACTERSNLS_CURRENCYNLS_[ISO|DUAL]_CURRENCYNLS_CALENDAR

TO_CHAR, TO_NCHAR

TO_NUMBER NLS_NUMERIC_CHARACTERSNLS_CURRENCYNLS_[ISO|DUAL]_CURRENCY

NLS_UPPER, NLS_LOWER,NLS_INITCAP, NLSSORT

NLS_SORT

2-25 Copyright © 2004, Oracle. All rights reserved.

Linguistic Sorting

Sort order can be affected by:

• Case sensitivity

• Diacritics or accent characters

• Combination characters that are treated as a single character

• Phonetics or character appearance

• Cultural preferences

2-26 Copyright © 2004, Oracle. All rights reserved.

Linguistic 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 character’s 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

2-27 Copyright © 2004, Oracle. All rights reserved.

Using Linguistic Sorting

You can specify the type of sort used for character data with the:

• NLS_SORT parameter– Default value is derived from the NLS_LANG

environment variable, if set– Can be specified for the session, client, or server

• NLSSORT function – Defines the sorting method at the query

level

2-29 Copyright © 2004, Oracle. All rights reserved.

Sorts That Are Not Case or Accent Sensitive

SELECT cust_last_name FROM oe.customersWHERE cust_last_name = 'de Funes';

SELECT cust_last_name FROM oe.customersWHERE cust_last_name = NLS_UPPER('de Funes');

ALTER SESSION SET NLS_COMP=ANSI;ALTER SESSION SET NLS_SORT=GENERIC_BASELETTER;

SELECT cust_last_name FROM oe.customersWHERE cust_last_name = 'De Funes';

2-30 Copyright © 2004, Oracle. All rights reserved.

Linguistic Comparisons

• Use the NLS_COMP parameter to:– Perform linguistic comparisons instead of binary

comparisons– Avoid cumbersome statements involving the

NLSSORT function

• NLS_COMP can be set to:

– BINARY– ANSI

SELECT word FROM listWHERE word > 'gf';

2-31 Copyright © 2004, Oracle. All rights reserved.

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_SORT parameter to match the linguistic definition 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;

2-32 Copyright © 2004, Oracle. All rights reserved.

Customizing Linguistic 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

2-33 Copyright © 2004, Oracle. All rights reserved.

Oracle Locale Builder

2-34 Copyright © 2004, Oracle. All rights reserved.

Character Set Scanner Utilities

• Character Set Scanner:– Scans the database to determine whether the

character set can be changed– Provides reports that detail possible problems and

fixes

• Language and Character Set File Scanner:– Determines the language and character set for

unknown file text– Uses probabilities to identify the dominant

language and character set

2-36 Copyright © 2004, Oracle. All rights reserved.

CREATE DATABASE ...CHARACTER SET WE8ISO8859P1NATIONAL CHARACTER SETUTF8...

% export NLS_LANG= American_America.US7ASCII

Data Conversion Between Client and Server Character Sets

C:/> set NLS_LANG= German_Germany.WE8DEC

2-37 Copyright © 2004, Oracle. All rights reserved.

NLS Data Conversion with Oracle Utilities

• Multiple data conversions can take place when data is exported 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

session character set specified by NLS_LANG.– Direct Path: Data is converted using client-side

directives.

2-39 Copyright © 2004, Oracle. All rights reserved.

NLS Data Conversion with Data Pump

• Data Pump Export always saves data in the same character set 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 specified by NLS_LANG for the session that started Data Pump.

2-40 Copyright © 2004, Oracle. All rights reserved.

Obtaining Character Set Information

SQL> SELECT parameter, value 2 FROM nls_database_parameters

3 WHERE parameter LIKE '%CHARACTERSET%';

PARAMETER VALUE----------------------- -------------NLS_CHARACTERSET WE8ISO8859P1NLS_NCHAR_CHARACTERSET AL16UTF16

2 rows selected.

2-41 Copyright © 2004, Oracle. All rights reserved.

Obtaining NLS Parameter Information

SQL> ALTER SESSION SET NLS_ISO_CURRENCY=FRANCE;

Session altered.

SQL> SELECT * FROM nls_instance_parameters

2 WHERE parameter LIKE '%ISO%';

PARAMETER VALUE----------------------- -------------NLS_ISO_CURRENCY AMERICA

SQL> SELECT * FROM nls_session_parameters

2 WHERE parameter LIKE '%ISO%';

PARAMETER VALUE----------------------- -------------NLS_ISO_CURRENCY FRANCE

2-42 Copyright © 2004, Oracle. All rights reserved.

Obtaining NLS Settings Information

• V$NLS_VALID_VALUES:Contains the values for NLS_LANGUAGE, NLS_SORT, NLS_TERRITORY and CHARACTERSET that are valid on your system

• V$NLS_PARAMETERS:– Contains the current NLS session settings,

including character sets– Used as the basis for NLS_SESSION_PARAMETERS

2-43 Copyright © 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:

• Customize language-dependent behavior for the database and individual sessions

• Specify different linguistic sorts for queries

• Retrieve data that matches a search string ignoring case or accent differences

• Obtain Globalization support configuration information

2-44 Copyright © 2004, Oracle. All rights reserved.

Practice 2 Overview: Using Globalization Support Features

This practice covers the following topics:

• Checking the database and national character set

• Identifying valid NLS values

• Setting NLS parameters

top related