GBase 8a从字符串转数字的函数to_number介绍和样例

GBase 8a数据库集群提供了to_number函数,用于从字符串转化成数字,本文介绍该函数的语法和说明,并提供使用样例。

语法

TO_NUMBER(expr)

说明

将字符串 expr 所包含的数据转化为 NUMBER 型数据。expr 的形式可为任何支持格式的字符串,如“111.0023”,“23,000,000”。

样例

数值必须是符合数字格式的,支持科学计数法。

gbase> select to_number('123.456');
+----------------------+
| to_number('123.456') |
+----------------------+
|              123.456 |
+----------------------+
1 row in set (Elapsed: 00:00:00.00)

gbase> select to_number('1.234E3');
+----------------------+
| to_number('1.234E3') |
+----------------------+
|                 1234 |
+----------------------+
1 row in set (Elapsed: 00:00:00.00)

不支持千分号,会被截断。

gbase> select to_number('1,234');
+--------------------+
| to_number('1,234') |
+--------------------+
|                  1 |
+--------------------+
1 row in set, 1 warning (Elapsed: 00:00:00.00)

gbase> show warnings;
+---------+------+-------------------------------------------+
| Level   | Code | Message                                   |
+---------+------+-------------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '1,234' |
+---------+------+-------------------------------------------+
1 row in set (Elapsed: 00:00:00.00)

gbase>

参考

相近功能

GBase 8a的强制类型转换cast和convert的用法例子

反向功能

GBase 8a从字符串转数字类型的几种方法

相关功能

GBase 8a时间转字符串类型的几种方法