开发者

first 3 digits of a string

开发者 https://www.devze.com 2023-01-15 03:26 出处:网络
What is the best way to know the first 3 digits of a string? I have written a function for the same. It is working as expected, but I will like to know if there is a better way to do this.

What is the best way to know the first 3 digits of a string? I have written a function for the same. It is working as expected, but I will like to know if there is a better way to do this.

mysql> select areacode_fun('233434535');
+---------------------------+
| areacode_fun('233434535') |
+---------------------------+
| 233                       |
+---------------------------+
1 row in set (0.00 sec)

mysql> select areacode_fun('2 33434535');
+----------------------------+
| areacode_fun('2 33434535') |
+-----------开发者_JAVA百科-----------------+
| 233                        |
+----------------------------+
1 row in set (0.00 sec)

mysql> select areacode_fun('2a33434535');
+----------------------------+
| areacode_fun('2a33434535') |
+----------------------------+
| 233                        |
+----------------------------+
1 row in set (0.00 sec)

mysql> select areacode_fun('(2a3)3434535');
+------------------------------+
| areacode_fun('(2a3)3434535') |
+------------------------------+
| 233                          |
+------------------------------+
1 row in set (0.00 sec)


Just thinking out loud, how about using regex?

SELECT '2a33434535' REGEXP '^[\+\-]?\d*\.?[Ee]?[\+\-]?\d*$';
0

精彩评论

暂无评论...
验证码 换一张
取 消