让我们首先创建一个表-
mysql> create table DemoTable ( Number text );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('7364746464,-'); mysql> insert into DemoTable values('-,8909094556');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+--------------+ | Number | +--------------+ | 7364746464,- | | -,8909094556 | +--------------+ 2 rows in set (0.00 sec)
以下是从MySQL的文本字段中提取数字的查询-
mysql> select replace(replace(replace(replace(Number, '-', ''), ' ', ''),'"',''),',','') as Result from DemoTable;
这将产生以下输出-
+------------+ | Result | +------------+ | 7364746464 | | 8909094556 | +------------+ 2 rows in set (0.00 sec)