|
compare()
The
string function
compare()
compares two
character strings
. Comparison is done on the basis of the
sort order
(Collating Sequence)
of the
character set
. This can be passed to the function either with the parameter "collation_name" or "collation_id".
Depending on the sort order, the string function compare() returns different values
Werte
.
-
"1"
indicates that "char_expression1" or "uchar_expression1" is greater than "char_expression2" or "uchar_expression2".
-
"0"
indicates that "char_expression1" or "uchar_expression1" is equal to
"char_expression2" or "uchar_expression2".
-
"-1"
indicates that "char_expression1" or "uchar_expression1" is less than "char_expression2" or "uchar_expression2".
Syntax of the string function compare()
compare ( {char_expression1 | uchar_expression1},
{char_expression2 | uchar_expression2} ),
[{collation_name | collation_id}]
The parameters of the string function compare()
"char_expression1" and "char_expression2"
The parameter "char_expression1" is being compared to the parameter "char_expression2". Both parameters must be passed either in single or double quotes.
Furthermore they can either be
variables
or
constants
and must be of on of these
datatypes:
char,
varchar,
nchar
or
nvarchar
.
"uchar_expression1" and "uchar_expression2"
The parameter "uchar_expression1" is compared to the parameter "uchar_expression2"
. Both parameters must be passed either in single or double quotes. Furthermore they can be either variables or constants and must be either of the following
datatypes:
unichar
or
univarchar
.
"collation_name" and "collation_id"
The parameter "collation_name" must be a valid name of a sort order (collating name), in single or double quotes. See table below for "collation names and ids". The "collation_id" can be used alternatively to the collation name. If the parameter "collation_name" or "collation_id" is not set, the function uses a binary sort order by default.
| collation names and ids |
| Description |
collation_name |
collation_id |
| Standard Unicode Multilingual |
Standard |
20 |
| Thai Dictionary Sort Order |
thaidict |
21 |
| ISO14651 Standard |
iso14651 |
22 |
| UTF-16 Sort Order – equivalent to UTF-8 Binary Sort Order |
utf8bin |
24 |
| CP 850 Alternative – "no accent" |
altnoacc |
39 |
| CP 850 Alternative – lower case characters first |
altdict |
45 |
| CP 850 Western European – Capitals ignored |
altnocsp |
46 |
| CP 850 Skandinavian – Dictionary Sort Order |
scandict |
47 |
| CP 850 Skandinavian – "case-insensitive" |
scannocp |
48 |
| GB Pinyin |
gbpinyin |
n/a |
| Binary Sort Order |
binary |
50 |
| Latin-1 English, French, German Dictionary Sort Order |
dict |
51 |
| Latin-1 English, French, German "no case" |
nocase |
52 |
| Latin-1 English, French, German "no case", "preference" |
nocasep |
53 |
| Latin-1 English, French, German "no accent" |
noaccent |
54 |
| Latin-1 Spanish Dictionary |
espdict |
55 |
| Latin-1 Spanish "no case" |
espnocs |
56 |
| Latin-1 Spanish "no accent" |
espnoac |
57 |
| ISO 8859-5 Russian Dictionary |
rusdict |
58 |
| ISO 8859-5 Russian "no case" |
rusnocs |
59 |
| ISO 8859-5 Cyrillic Dictionary |
cyrdict |
63 |
| ISO 8859-5 Cyrillic "no case" |
cyrnocs |
64 |
| ISO 8859-7 Greek Dictionary |
elldict |
65 |
| ISO 8859-2 Hungrian Dictionary |
hundict |
69 |
| ISO 8859-2 Hungarian "no accents" |
hunnoac |
70 |
| ISO 8859-2 Hungarian "no case" |
hunnocs |
71 |
| ISO 8859-9 Turkish Dictionary |
turdict |
72 |
| ISO 8859-9 Turkish "no accents" |
turknoac |
73 |
| ISO 8859-9 Turkish "no case" |
turknocs |
74 |
| CP932 Binary Sort Order |
cp932bin |
129 |
| Chinese Phonetic Sort Order |
dynix |
130 |
| GB2312 Binary Sort Order |
gb2312bn |
137 |
| Regular Cyrillic Dictionary |
cyrdict |
140 |
| Turkish Dictionary |
turdict |
155 |
| EUCKSC Binary Sort Order |
euckscbn |
161 |
| Chinese Phonectic Sort Order |
gbpinyin |
163 |
| Russian Dictionary Sort Order |
rusdict |
165 |
| SJIS Binary Sort Order |
sjisbin |
179 |
| EUCJIS Binary Sort Order |
eucjisbn |
192 |
| BIG5 Binary Sort Order |
big5bin |
194 |
| Shift-JIS Binary Sort Order |
sjisbin |
259 |
Example for the string function compare()
select compare("abc", "xyz")
go
-----
-1
Returns "-1", because the value "abc" is less than "xyz".
select compare("abc", "abc")
go
-----
0
Returns "0", because the value of "abc" is equal to "abc".
select compare("xyz", "abc")
go
-----
1
Returns "1", because the value of "xyz" is greater than "abc".
select compare("xyz", "abc", "binary")
go
-----
1
Binary sort order. Returns "1", because the value of "xyz" is greater than "abc".
select compare(("xyz"), ("abc"), (50))
go
-----
1
Here, as an alternative to binary sorting, the "collating_id" is passed to compare().
Returns "1", because the value of "xyz" is greater than "abc".
Problems with the string function compare()
When comparing two values, the function compare() can produce up to six
bytes
of information for each character to be compared.
Thus it can happen that the storage limit is reached.
In this case the result is returned truncated.
If this happens, a warning will be returned, the
query
or
transaction
will not be aborted though and continue to execute. The storage limit of the string function depends on the
Page Size
of
ASE®s
. If the return value needs to be truncated due to lack of storage space, the return value adapts to the maximum storage capacity of the corresponding
DOL
and
APL
tables.
| Locking scheme
| Page size
| Maximum row length
| Maximum column length
|
|
2K (2048 bytes) |
1962 |
1960 bytes |
| 4K (4096 bytes) |
4010 |
4008 bytes |
| APL tables |
8K (8192 bytes) |
8106 |
8104 bytes |
| 16K (16384 bytes) |
16298 |
16296 bytes |
| 2K (2048 bytes) |
1964 |
1958 bytes |
| 4K (4096 bytes) |
4012 |
4006 bytes |
| DOL tables |
8K (8192 bytes) |
8108 |
8102 bytes |
| 16K (16384 bytes) |
16300 |
16294 bytes* |
| 16K (16384 bytes) |
16300** |
8191-6-2 = 8183 bytes*** |
* if the table does not contain columns with variable datatypes.
** subject to a max start offset of varlen = 8191.
*** if the table contains at least one column with variable datatypes. The size is equal to 6 bytes
for the row overhead and 2 bytes for the field length.
|
See also:
ASE T-SQL - Aggregate Functions, ascii(), char(), char(n), charindex(), char_length(), difference(), lower(), ltrim(), patindex(), replicate(), reverse(), right(), rtrim(), sortkey(), soundex(), space(), str(), String Functions, stuff(), substring(), to_unichar(), uhighsurr(), ulowsurr(), upper(), uscalar().
|