Tuesday, August 26, 2008

Character Set

The query below generated the data shown in the table using the DUMP statement. SQL*Plus dumped in a straight line as normal. I used Google Docs to format it into a table.

.

CharAscii DecimalOctalHexCharAscii DecimalOctalHexCharAscii DecimalOctalHexCharAscii DecimalOctalHex

.

space3240200486030A6510141a9714161

.

!3341211496131B6610242b9814262

.

"3442222506232C6710343c9914363

.

$3644243516333D6810444d10014464

.

%3745254526434E6910545e10114565

.

&3846265536535F7010646f10214666

.

'3947276546636G7110747g10314767

.

(4050287556737H7211048h10415068

.

)4151298567038I7311149i10515169

.

*42522a9577139J741124aj1061526a

.

+43532bK751134bk1071536b

.

,44542c[911335bL761144cl1081546c

.

-45552d\921345cM771154dm1091556d

.

.46562e]931355dN781164en1101566e

.

/47572f^941365eO791174fo1111576f

.

_951375fP8012050p11216070

.

:58723a`9614060Q8112151q11316171

.

;59733bR8212252r11416272

.

<60743c{1231737bS8312353s11516373

.

=61753d|1241747cT8412454t11616474

.

>62763e}1251757dU8512555u11716575

.

?63773fV8612656v11816676

.

@6410040W8712757w11916777

.

X8813058x12017078

.

Y8913159y12117179

.

Z901325az1221727a
rem +--------------------------------------------------------------------------+
rem | Script ID: Dump.sql
rem | Purpose: Show how dump works and dump all characters in all sets.
rem |
rem | Developer: Lynn Tobias
rem | Script Date: 8/26/2008
rem | Oracle Ver: 10g
rem +--------------------------------------------------------------------------+

Set Serveroutput On
Declare
V_Outputstr Varchar2(50) ;

Begin
Dbms_Output.Put_Line(Rpad('Char',5)|| Rpad('Ascii',6)|| 'Octal Decimal Hex');

For V_Ctr In 1..94 Loop

Select Lpad(Substr(Dump(Substr(Charx,V_Ctr,1),17),Instr(Dump(Substr(Charx,V_Ctr,1),17),': ',11)+2),4) ||
Lpad(Substr(Dump(Substr(Charx,V_Ctr,1), 3),Instr(Dump(Substr(Charx,V_Ctr,1), 3),': ',11)+2),5) ||
Lpad(Substr(Dump(Substr(Charx,V_Ctr,1), 8),Instr(Dump(Substr(Charx,V_Ctr,1), 8),': ',11)+2),6) ||
Lpad(Substr(Dump(Substr(Charx,V_Ctr,1),10),Instr(Dump(Substr(Charx,V_Ctr,1),10),': ',11)+2),8) ||
Lpad(Substr(Dump(Substr(Charx,V_Ctr,1),16),Instr(Dump(Substr(Charx,V_Ctr,1),16),': ',11)+2),4)
Into V_Outputstr
From ( ------------- This is the list of characters we want to evaluate -------------------------
Select
' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
As Charx
From Dual
);

Dbms_Output.Put_Line(V_Outputstr);
End Loop;
End;
/
-- How the lines starting with LPad work:
-- 1 Substr(Charx,V_Ctr,1) get one character at a time from the string based on the counter
-- 2 Dump(Substr(Charx,V_Ctr,1),10) dump to get this string: 'Typ=1 Len=1: 97'
-- 3 Instr(Dump(Substr(Charx,V_Ctr,1),10),':',11) find the position of the ':' in the string
-- 4 Instr(Dump(Substr(Charx,V_Ctr,1),10),':',11)+2 Add 2 to get the beginning position of the character (i.e., 97)
-- 5 Substr (Search Item 2 ,Starting at position calculated in Item 4)
-- 6 LPad it so different length characters line up.

No comments:

Post a Comment