05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 12 ■ DATATYPES 493<br />

(in this example, the set of 8-bit characters) into a smaller set (that of the 7-bit characters).<br />

This is a lossy conversion—the characters get modified because it is quite simply not possible<br />

to represent every character. But this conversion must take place. If the database is storing<br />

data in a single-byte character set but the client (say, a Java application, since the Java language<br />

uses Unicode) expects it in a multibyte representation, then it must be converted<br />

simply so the client application can work with it.<br />

You can see character set conversion very easily. For example, I have a database whose<br />

character set is set to WE8ISO8859P1, a typical Western European character set:<br />

ops$tkyte@ORA10G> select *<br />

2 from nls_database_parameters<br />

3 where parameter = 'NLS_CHARACTERSET';<br />

PARAMETER<br />

VALUE<br />

------------------------------ ----------------------------------------<br />

NLS_CHARACTERSET<br />

WE8ISO8859P1<br />

Now, if I ensure my NLS_LANG is set the same as my database character set (Windows users<br />

would change/verify this setting in their registry) as follows:<br />

ops$tkyte@ORA10G> host echo $NLS_LANG<br />

AMERICAN_AMERICA.WE8ISO8859P1<br />

then I can create a table <strong>and</strong> put in some “8-bit” data. This data that will not be usable by a<br />

7-bit client that is expecting only 7-bit ASCII data:<br />

ops$tkyte@ORA10G> create table t ( data varchar2(1) );<br />

Table created.<br />

ops$tkyte@ORA10G> insert into t values ( chr(224) );<br />

1 row created.<br />

ops$tkyte@ORA10G> insert into t values ( chr(225) );<br />

1 row created.<br />

ops$tkyte@ORA10G> insert into t values ( chr(226) );<br />

1 row created.<br />

ops$tkyte@ORA10G> select data, dump(data) dump<br />

2 from t;<br />

D DUMP<br />

- --------------------<br />

à Typ=1 Len=1: 224<br />

á Typ=1 Len=1: 225<br />

â Typ=1 Len=1: 226<br />

ops$tkyte@ORA10G> commit;<br />

Now, if I go to another window <strong>and</strong> specify “a 7-bit ASCII” client, I’ll see quite different<br />

results:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!