Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Oracle Database 11g.pdf
Скачиваний:
78
Добавлен:
10.06.2015
Размер:
12.69 Mб
Скачать

776  Appendix A  n  Lab Exercises

Lab 13.3: Performing Linguistic Sorts

In this exercise, you will create a table and populate it with values that are easily sorted. You will then modify the NLS parameters that affect linguistic sorts and query the table, observing how the NLS-parameter settings modify the sort results. Here are the steps:

1.Create a table for linguistic sorts, and populate it.

2.Verify your session NLS parameters.

3.Query the sort table.

4.Modify the sort parameter.

5.Query the table and observe the differences in the sort results. Here’s an example:

1.Create a table for linguistic sorts, and populate it.

SQL> create table linguistic_sort_test (x number, y varchar2(1)); Table created.

SQL>

insert into linguistic_sort_test values (1,’A’); insert into linguistic_sort_test values (2,’B’); insert into linguistic_sort_test values (3,’C’); insert into linguistic_sort_test values (4,’D’); insert into linguistic_sort_test values (5,’E’); insert into linguistic_sort_test values (6,’F’); insert into linguistic_sort_test values (7,’G’); insert into linguistic_sort_test values (8,’H’); insert into linguistic_sort_test values (9,’I’); insert into linguistic_sort_test values (10,’J’); insert into linguistic_sort_test values (11,’a’); insert into linguistic_sort_test values (12,’b’); insert into linguistic_sort_test values (13,’c’); insert into linguistic_sort_test values (14,’d’); insert into linguistic_sort_test values (15,’e’); insert into linguistic_sort_test values (16,’f’); insert into linguistic_sort_test values (17,’g’); insert into linguistic_sort_test values (18,’h’); insert into linguistic_sort_test values (19,’i’); insert into linguistic_sort_test values (20,’j’); commit;

Lab 13.3: Performing Linguistic Sorts 

777

2.Verify your session NLS parameters.

SQL> select * from nls_session_parameters; PARAMETER VALUE

------------------------------

----------------------------

NLS_LANGUAGE

AMERICAN

NLS_TERRITORY

AMERICA

NLS_CURRENCY

$

NLS_ISO_CURRENCY

AMERICA

NLS_NUMERIC_CHARACTERS

.,

NLS_CALENDAR

GREGORIAN

NLS_DATE_FORMAT

dd-mon-yyyy hh24:mi:ss

NLS_DATE_LANGUAGE

AMERICAN

NLS_SORT

BINARY

NLS_TIME_FORMAT

HH.MI.SSXFF AM

NLS_TIMESTAMP_FORMAT

DD-MON-RR HH.MI.SSXFF AM

NLS_TIME_TZ_FORMAT

HH.MI.SSXFF AM TZR

NLS_TIMESTAMP_TZ_FORMAT

DD-MON-RR HH.MI.SSXFF AM TZR

NLS_DUAL_CURRENCY

$

NLS_COMP

BINARY

NLS_LENGTH_SEMANTICS

BYTE

NLS_NCHAR_CONV_EXCP

FALSE

17 rows selected.

 

SQL>

3.Query the sort table. Order by the numeric value as a baseline or control query, and then order by the character column using the default BINARY sort.

SQL> select * from linguistic_sort_test order by x;

X Y

---------- -

1

A

2

B

3

C

4

D

5

E

6

F

7

G

778  Appendix A  n  Lab Exercises

8 H

9 I

10J

11a

12b

13c

14d

15e

16f

17g

18h

19i

20j

20 rows selected.

SQL>

SQL> select * from linguistic_sort_test order by y;

X Y

---------- -

1

A

2

B

3

C

4

D

5

E

6

F

7

G

8

H

9

I

10

J

11

a

12

b

13

c

14

d

15

e

16

f

17

g

Lab 13.3: Performing Linguistic Sorts 

779

18h

19i

20j

20 rows selected.

4.Modify the sort parameter. The default was BINARY; we’ll modify it to EBCDIC to demonstrate the simple difference.

SQL>

SQL> alter session set nls_sort=’EBCDIC’; Session altered.

5.Query the table and observe the differences in the sort results from the previous query.

SQL> select * from linguistic_sort_test order by y;

X Y

---------- -

11a

12b

13c

14d

15e

16f

17g

18h

19i

20j 1 A 2 B 3 C 4 D 5 E 6 F 7 G 8 H 9 I

10 J

20 rows selected.

780  Appendix A  n  Lab Exercises

Notice that the EBCDIC sort placed the lowercase letters at the beginning of the sort because they have a lower EBCDIC value than their uppercase counterparts.

If we now set the NLS_SORT value to ASCII7, you’ll see the same results as BINARY for this simple sort.

SQL> alter session set nls_sort=’ASCII7’;

Session altered.

SQL> select * from linguistic_sort_test order by y;

X Y

---------- -

1

A

2

B

3

C

4

D

5

E

6

F

7

G

8

H

9

I

10

J

11

a

12

b

13

c

14

d

15

e

16

f

17

g

18

h

19

i

20

j

20 rows selected.

Now if you set the NLS_SORT to CROATIAN, you’ll see something really interesting.

SQL> alter session set nls_sort=’CROATIAN’;

Lab 13.3: Performing Linguistic Sorts 

781

Session altered.

SQL> select * from linguistic_sort_test order by y;

X Y

---------- -

1 A

11a 2 B

12b 3 C

13c 4 D

14d 5 E

15e 6 F

16f 7 G

17g 8 H

18h 9 I

19i

10J

20j

20 rows selected.

SQL>

And when you set NLS_SORT to THAI_M, you’ll see the opposite pattern from the one for CROATIAN.

SQL> alter session set nls_sort=’THAI_M’;

Session altered.

SQL> select * from linguistic_sort_test order by y;

782  Appendix A  n  Lab Exercises

X Y

---------- -

11a 1 A

12b 2 B

13c 3 C

14d 4 D

15e 5 E

16f 6 F

17g 7 G

18h 8 H

19i 9 I

20j

10J

20 rows selected.

SQL>

Remember that setting NLS_LANGUAGE will override the NLS_SORT setting, but NLS_SORT can be set to whatever valid setting you choose following a change to NLS_LANGUAGE.

Appendix

About the

B

Companion CD

 

In this appendix:

 

ÛÛWhat you’ll find on the CD

 

ÛÛSystem requirements

 

ÛÛUsing the CD

 

ÛÛTroubleshooting

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]