§ Oracle兼容-函数-INITCAP()函数


§ 1. 语法

INITCAP(string)
1

§ 2. 定义和用法

INITCAP() 函数的作用是将字符串中的每个单词的首字母转为大写,其他字母转为小写。每个单词由空格或除字母和数字之外的字符分隔开。

  • 在GreatSQL中,当string中包含转义字符(\0 \' \" '' \\ \b \B \n \N \r \R \t \T \z \Z)时,不会被当做2个字符,而是当做1个字符来处理。这会导致GreatSQL和Oracle的结果存在差异,在ORACLE中转义字符在 INITCAP() 函数处理后输出2个字符,比如:INITCAP('\n') 结果为 \N,而在GreatSQL中转义字符在 INITCAP() 函数处理后输出1个字符,比如:INITCAP('\n') 结果为 换行
  • 当参数 string 是数值类型时,不会将输出结果转为科学计数法。另外,如果 string 超过81个数字,会导致溢出截断,此时结果为 65个9

§ 3. 示例

greatsql> SELECT INITCAP('hello world');
+------------------------+
| INITCAP('hello world') |
+------------------------+
| Hello World            |
+------------------------+

greatsql> SELECT INITCAP('hello你好world');
+-----------------------------+
| INITCAP('hello你好world')   |
+-----------------------------+
| Hello你好World              |
+-----------------------------+

greatsql> SELECT INITCAP('hello123world');
+--------------------------+
| INITCAP('hello123world') |
+--------------------------+
| Hello123world            |
+--------------------------+

greatsql> SELECT INITCAP(NULL);
+------------------------------+
| INITCAP(NULL)                |
+------------------------------+
| NULL                         |
+------------------------------+

greatsql> SELECT INITCAP('hello\nworld');
+-------------------------+
| INITCAP('hello\nworld') |
+-------------------------+
| Hello
World             |
+-------------------------+

greatsql> SELECT INITCAP('hello\1world');
+-------------------------+
| INITCAP('hello\1world') |
+-------------------------+
| Hello1world             |
+-------------------------+

greatsql> SELECT INITCAP('àabcd abÀcd abcdÀ');
+---------------------------------+
| INITCAP('àabcd abÀcd abcdÀ')    |
+---------------------------------+
| Àabcd Abàcd Abcdà               |
+---------------------------------+

greatsql> SELECT INITCAP(111111111111111111111111111111111111111111111111111111111111111111111111111111111);
+--------------------------------------------------------------------------------------------+
| INITCAP(111111111111111111111111111111111111111111111111111111111111111111111111111111111) |
+--------------------------------------------------------------------------------------------+
| 111111111111111111111111111111111111111111111111111111111111111111111111111111111          |
+--------------------------------------------------------------------------------------------+

greatsql> SELECT INITCAP(1111111111111111111111111111111111111111111111111111111111111111111111111111111111);
+---------------------------------------------------------------------------------------------+
| INITCAP(1111111111111111111111111111111111111111111111111111111111111111111111111111111111) |
+---------------------------------------------------------------------------------------------+
| 99999999999999999999999999999999999999999999999999999999999999999                           |
+---------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

greatsql> SHOW WARNINGS;
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect DECIMAL value: '111111111111111111111111111111111111111111111111111111111111111111111111111111111' |
+---------+------+------------------------------------------------------------------------------------------------------------------------+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

扫码关注微信公众号

greatsql-wx