|
Posted on 2005-11-23 17:18 非鱼 阅读(3617) 评论(0) 编辑 收藏 所属分类: Sybase
Sybase Adaptive Server
Enterprise在中文支持方面,提供的排序方式比较单一。如果使用CP850(支持GB2312标准),排序方式是比较多的。但GB2312的汉字
库太小,多数情况下,我们至少要使用CP936甚至GB18030字符集。在使用CP936、GB18030字符集时,你只有BINARY方式的排序可以
选择。 问题是,如果一个早期应该使用CP850+大小写不敏感方式的排序,在升级到新的字符集+BINARY排序时,程序中的大小写要改成敏感的。 类似的问题可以通过修改SYBASE的相应字符集下的排序文件解决。你甚至可以定义自己的排序方式。 首先我们来看看GB18030字符集的BINARY排序。BINARY排序对应的是$SYB_HOME/charsets/gb18030/binary.srt,用文本编辑器打开这个文件,可以看到其内容如下:
1 ; semi-colon is the comment character 2 [sortorder] 3 ;=============================================================================== 4 ; 5 ; Sort Order Overview: 6 ; -------------------- 7 ; Based on the gb18030 simplified Chinese character set, this sort 8 ; order is a binary ordering. 9 ; 10 ;=============================================================================== 11 12 class = 0x01 ; Class `1' sort order 13 id = 0x32 ; id = 50 14 name = bin_gb18030 15 menuname = "Binary ordering, for gb18030." 16 charset = gb18030 17 18 description = "Binary sort order for simplified Chinese using gb18030." 19 20 binary = "true" 21 Class、id、name、menuname、charset、description都不用修改,而binary=true则指明使用binary方式排序,其实这句等价于对01~FF每个字符都进行定义。 其
次,看一下其他字符集中的大小写不敏感的排序文件,如$SYB_HOME/charsets/iso_1/noaccents.srt,具体内容就不写
了。可以发现大小写不敏感只是设置a, A;b, B等字符相等。参考这个排序文件,我们就可以这样定义binary.srt: 1. 设置a=A...z=Z; 2. 定义其他字符。 这样修改之后,就支持GB18030下的大小写不敏感排序了。 修改排序文件后,需要使用加裁该字符集和排序: charset -Usa -Ppassword -Sserver sort_order_file charset_name 然后在isql中用sp_configure 'default sortorder id', 文件中的id(十进制),两次重启SYBASE后修改字符集排序就完成了。
这种方法适用于ASE11.9.2~15.0各个版本,经历了实践考验。
另外对于早期版本,没有CP936和GB18030,可以从15.0拷一个过去用。 下面附上我修改的GB18030, BINARY.SRT文件内容:
1 ; semi-colon is the comment character 2 [sortorder] 3 ;=============================================================================== 4 ; 5 ; Sort Order Overview: 6 ; -------------------- 7 ; Based on the cp936 simplified Chinese character set, this sort 8 ; order is a binary ordering. 9 ; 10 ;=============================================================================== 11 12 class = 0x01 ; Class `1' sort order 13 id = 0x32 ; id = 50 14 name = bin_gb18030 15 menuname = "Binary ordering, for gb18030." 16 charset = gb18030 17 ;preference = false ; Do not use preference 18 19 description = "Binary sort order for simplified Chinese using gb18030." 20 ; Ligatures 21 22 ;lig = 0xC6=0xE6, after ae ; AE, ae ligature 23 ;lig = 0xDF, after ss ; small german letter sharp s 24 25 ; Control characters 26 27 char = 0x01 ;(SOH) start of heading 28 char = 0x02 ;(STX) start of text 29 char = 0x03 ;(ETX) end of text 30 char = 0x04 ;(EOT) end of transmission 31 char = 0x05 ;(ENQ) enquiry 32 char = 0x06 ;(ACK) acknowledge 33 char = 0x07 ;(BEL) bell 34 char = 0x08 ;(BS) backspace 35 char = 0x09 ;(HT) horizontal tab 36 char = 0x0A ;(LF) newline, or line feed 37 char = 0x0B ;(VT) vertical tab 38 char = 0x0C ;(FF) form feed 39 char = 0x0D ;(CR) carriage return 40 char = 0x0E ;(SO) shift out 41 char = 0x0F ;(SI) shift in 42 char = 0x10 ;(DLE) data link escape 43 char = 0x11 ;(DC1) device control 1 44 char = 0x12 ;(DC2) device control 2 45 char = 0x13 ;(DC3) device control 3 46 char = 0x14 ;(DC4) device control 4 47 char = 0x15 ;(NAK) negative acknowledge 48 char = 0x16 ;(SYN) synchronous idle 49 char = 0x17 ;(ETB) end transmission blk 50 char = 0x18 ;(CAN) cancel 51 char = 0x19 ;(EM) end of medium 52 char = 0x1A ;(SUB) substitute 53 char = 0x1B ;(ESC) escape 54 char = 0x1C ;(FS) file separator 55 char = 0x1D ;(GS) group separator 56 char = 0x1E ;(RS) record separator 57 char = 0x1F ;(US) unit separator 58 59 ; All non-alphanumeric characters, including puntuation 60 ; These are sorted merely by their numerical ordering 61 ; based on the ISO 8859-1 standard for clarity and 62 ; consistency 63 64 char = 0x20 ;( ) space 65 char = 0x21 ;(!) exclamation mark 66 char = 0x22 ;(") quotation mark 67 char = 0x23 ;(#) number sign 68 char = 0x24 ;($) dollar sign 69 char = 0x25 ;(%) percent sign 70 char = 0x26 ;(&) ampersand 71 char = 0x27 ;(') apostrophe 72 char = 0x28 ;(() left parenthesis 73 char = 0x29 ;()) right parenthesis 74 char = 0x2A ;(*) asterisk 75 char = 0x2B ;(+) plus sign 76 char = 0x2C ;(,) comma 77 char = 0x2D ;(-) hyphen, minus sign 78 char = 0x2E ;(.) full stop 79 char = 0x2F ;(/) solidus 80 char = 0x3A ;(:) colon 81 char = 0x3B ;(;) semicolon 82 char = 0x3C ;(<) less-than sign 83 char = 0x3D ;(=) equals sign 84 char = 0x3E ;(>) greater-than sign 85 char = 0x3F ;(?) question mark 86 char = 0x40 ;(@) commercial at 87 char = 0x5B ;([) left square bracket 88 char = 0x5C ;(\) reverse solidus 89 char = 0x5D ;(]) right square bracket 90 char = 0x5E ;(^) circumflex accent 91 char = 0x5F ;(_) low line 92 char = 0x60 ;(`) grave accent 93 char = 0x7B ;({) left curly bracket 94 char = 0x7C ;(|) vertical line 95 char = 0x7D ;(}) right curly bracket 96 char = 0x7E ;(~) tilde 97 char = 0x7F ;delete, or rubout 98 char = 0x80 ; undefined 99 char = 0x81 ; undefined 100 char = 0x82 ; undefined 101 char = 0x83 ; undefined 102 char = 0x84 ; undefined 103 char = 0x85 ; undefined 104 char = 0x86 ; undefined 105 char = 0x87 ; undefined 106 char = 0x88 ; undefined 107 char = 0x89 ; undefined 108 char = 0x8A ; undefined 109 char = 0x8B ; undefined 110 char = 0x8C ; undefined 111 char = 0x8D ; undefined 112 char = 0x8E ; undefined 113 char = 0x8F ; undefined 114 char = 0x90 ; undefined 115 char = 0x91 ; undefined 116 char = 0x92 ; undefined 117 char = 0x93 ; undefined 118 char = 0x94 ; undefined 119 char = 0x95 ; undefined 120 char = 0x96 ; undefined 121 char = 0x97 ; undefined 122 char = 0x98 ; undefined 123 char = 0x99 ; undefined 124 char = 0x9A ; undefined 125 char = 0x9B ; undefined 126 char = 0x9C ; undefined 127 char = 0x9D ; undefined 128 char = 0x9E ; undefined 129 char = 0x9F ; undefined 130 char = 0xA0 ;no-break space 131 char = 0xA1 ;inverted exclamation mark 132 char = 0xA2 ;cent sign 133 char = 0xA3 ;pound sign 134 char = 0xA4 ;currency sign 135 char = 0xA5 ;yen sign 136 char = 0xA6 ;broken bar 137 char = 0xA7 ;paragraph sign, section sign 138 char = 0xA8 ;diaeresis 139 char = 0xA9 ;copyright sign 140 char = 0xAA ;feminine ordinal indicator 141 char = 0xAB ;left angle quotation mark 142 char = 0xAC ;not sign 143 char = 0xAD ;soft hyphen 144 char = 0xAE ;registered trade mark sign 145 char = 0xAF ;macron 146 char = 0xB0 ;ring above or degree sign 147 char = 0xB1 ;plus/minus (+/-) sign 148 char = 0xB2 ;superscript 2 149 char = 0xB3 ;superscript 3 150 char = 0xB4 ;acute accent 151 char = 0xB5 ;micro sign 152 char = 0xB6 ;pilcrow or paragraph sign 153 char = 0xB7 ;middle dot 154 char = 0xB8 ;cedilla 155 char = 0xB9 ;superscript 1 156 char = 0xBA ;masculine ordinal indicator 157 char = 0xBB ;right angle quotation mark 158 char = 0xBC ;vulgar fraction one quarter 159 char = 0xBD ;vulgar fraction one half 160 char = 0xBE ;vulgar fraction three quarter 161 char = 0xBF ;inverted question mark 162 char = 0xC0 163 char = 0xC1 164 char = 0xC2 165 char = 0xC3 166 char = 0xC4 167 char = 0xC5 168 char = 0xC6 169 char = 0xC7 170 char = 0xC8 171 char = 0xC9 172 char = 0xCA 173 char = 0xCB 174 char = 0xCC 175 char = 0xCD 176 char = 0xCE 177 char = 0xCF 178 char = 0xD0 179 char = 0xD1 180 char = 0xD2 181 char = 0xD3 182 char = 0xD4 183 char = 0xD5 184 char = 0xD6 185 char = 0xD7 ;multiplication sign 186 char = 0xD8 187 char = 0xD9 188 char = 0xDA 189 char = 0xDB 190 char = 0xDC 191 char = 0xDD 192 char = 0xDE 193 char = 0xDF 194 char = 0xE0 195 char = 0xE1 196 char = 0xE2 197 char = 0xE3 198 char = 0xE4 199 char = 0xE5 200 char = 0xE6 201 char = 0xE7 202 char = 0xE8 203 char = 0xE9 204 char = 0xEA 205 char = 0xEB 206 char = 0xEC 207 char = 0xED 208 char = 0xEE 209 char = 0xEF 210 char = 0xF0 211 char = 0xF1 212 char = 0xF2 213 char = 0xF3 214 char = 0xF4 215 char = 0xF5 216 char = 0xF6 217 char = 0xF7 218 char = 0xF8 219 char = 0xF9 220 char = 0xFA 221 char = 0xFB 222 char = 0xFC 223 char = 0xFD 224 char = 0xFE 225 char = 0xFF 226 227 ; Digits 228 229 char = 0x30 ;(0) digit zero 230 char = 0x31 ;(1) digit one 231 char = 0x32 ;(2) digit two 232 char = 0x33 ;(3) digit three 233 char = 0x34 ;(4) digit four 234 char = 0x35 ;(5) digit five 235 char = 0x36 ;(6) digit six 236 char = 0x37 ;(7) digit seven 237 char = 0x38 ;(8) digit eight 238 char = 0x39 ;(9) digit nine 239 240 ; Latin Alphabet 241 242 char = 0x41=0x61 243 ;A, a, A-grave, a-grave, A-acute, a-acute, A-circumflex, a-circumflex, 244 ;A-tilde, a-tilde, ;A-diaeresis, a-diaeresis, A-ring, a-ring 245 char = 0x42=0x62 ;letter B, b 246 char = 0x43=0x63 247 char = 0x44=0x64 ;letter D, d 248 char = 0x45=0x65 249 ;E, e, E-grave, e-grave, E-acute, e-acute, E-circumflex, e-circumflex, 250 ;E-diaeresis, e-diaeresis 251 char = 0x46=0x66 ;letter F, f 252 char = 0x47=0x67 ;letter G, g 253 char = 0x48=0x68 ;letter H, h 254 char = 0x49=0x69 255 ;I, i, I-grave, i-grave, I-acute, i-acute, I-circumflex, i-circumflex, 256 ;I-diaeresis, i-diaeresis 257 char = 0x4A=0x6A ;letter J, j 258 char = 0x4B=0x6B ;letter K, k 259 char = 0x4C=0x6C ;letter L, l 260 char = 0x4D=0x6D ;letter M, m 261 char = 0x4E=0x6E 262 char = 0x4F=0x6F 263 ;O, o, O-grave, o-grave, O-acute, o-acute, O-circumflex, o-circumflex, 264 ;O-tilde, o-tilde, O-diaeresis, o-diaeresis, O-stroke, o-stroke 265 char = 0x50=0x70 ;letter P, p 266 char = 0x51=0x71 ;letter Q, q 267 char = 0x52=0x72 ;letter R, r 268 char = 0x53=0x73 ;letter S, s 269 char = 0x54=0x74 ;letter T, t 270 char = 0x55=0x75 271 ;U, u, U-grave, u-grave, U-acute, u-acute, U-circumflex, u-circumflex, 272 ;U-diaeresis, u-diaeresis 273 char = 0x56=0x76 ;letter V, v 274 char = 0x57=0x77 ;letter W, w 275 char = 0x58=0x78 ;letter X, x 276 char = 0x59=0x79 277 char = 0x5A=0x7A ;letter Z, z 278 279 ; Alpha characters not used in English, French or German: 280 281 ;char = 0xD0=0xF0 ;icelandic capital letter eth, small letter eth 282 ;char = 0xDE=0xFE ;icelandic capital letter thorn, small letter thorn 283
|