1
了解字符串的前3位数字的最佳方法是什么? 我写了一个相同的功能。它按预期工作,但我想知道是否有更好的方法来做到这一点。字符串的前3位数
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') |
+----------------------------+
| 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)
为什么不发布你的代码呢? – dirkgently 2010-09-06 08:01:08
这是在进入数据库之前你应该做的一种输入验证 – 2010-09-06 08:03:01
有了像你这样的自定义逻辑,我想你的函数做的是正确的,没问题。如果您希望在单个SQL查询中获得解决方案,那么它可能无济于事。如果你发布了你的功能,那么人们至少可以帮助优化它。 – 2010-09-06 08:04:45