oracle 11g sql MAX() 如何用于 varchar

oracle 11g sql how MAX() works for varchar

我将这些值存储为 Varchar:

00
0
NEE-01
LAH-01

MAX() 函数如何确定哪个是 "more" MAX()?非常感谢!

较高的值由基于排序规则的字母排序决定。 L 出现在 N 之前,因此,NEE-01 将是给定数据的 "max",而 LAH-01 将是 "min"。

这与您使用 order by some_varchar_column

时应用的规则相同

As documented in the manual

Character values are compared on the basis of two measures:

  • Binary or linguistic sorting

  • Blank-padded or nonpadded comparison semantics

然后再往下:

In binary comparison, which is the default, Oracle compares character strings according to the concatenated value of the numeric codes of the characters in the database character set. One character is greater than another if it has a greater numeric value than the other in the character set. Oracle considers blanks to be less than any character, which is true in most character sets

(强调我的)

所以默认的二进制比较会考虑字符的 ASCII 值。这也意味着大写字符被认为是 "higher" 然后是小写字符。

由于字母排序。例如:1. A, 2. B ... Z. 26
确定更高的值。
例如:
最大(col1)和 Col1:

XABC
XYZY

结果:
XYZY
XABC