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


§ 1. 语法

INITCAP(string)

§ 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' |
+---------+------+------------------------------------------------------------------------------------------------------------------------+

§ 问题反馈

§ 联系我们

扫码关注微信公众号

greatsql-wx