如何删除字符串开头的所有空格?

时间:2018-06-25 11:49:38

标签: mysql sql

我有一张这样的桌子:

// posts
+----+--------------+
| id |  subject     |
+----+--------------+
| 1  |    subject 1 |
| 2  | subject 2    |
| 3  |   subject 3  |
| 4  |  subject 4   |
| 5  | subject 5    |
+----+--------------+

我需要删除subject列开头的所有空格。这是我当前的代码:

UPDATE posts set subject = REPLACE(subject, ' ', '') WHERE 1;

这是当前结果:

+----+--------------+
| 1  | subject1     |
| 2  | subject2     |
| 3  | subject3     |
| 4  | subject4     |
| 5  | subject5     |
+----+--------------+

这是预期结果:

+----+--------------+
| 1  | subject 1    |
| 2  | subject 2    |
| 3  | subject 3    |
| 4  | subject 4    |
| 5  | subject 5    |
+----+--------------+

看到了吗?仅应删除字符串开头的空格。注意,正则表达式(我在PHP中测试过)^中有一个东西,正是我想要的东西。但是我不知道如何在MySQL中使用它。有想法吗?

2 个答案:

答案 0 :(得分:2)

mysql> select ltrim('      abc');
+--------------------+
| ltrim('      abc') |
+--------------------+
| abc                |
+--------------------+

答案 1 :(得分:2)

使用@objc let biometricsAuthPolicy = LAPolicy.deviceOwnerAuthenticationWithBiometrics @objc func supportsFaceID() -> Bool { if #available(iOS 11.0, *) { return biometryType() == .faceID // return biometryType() == .typeFaceID for Xcode 9.1 } return false } @objc func supportsTouchID() -> Bool { if #available(iOS 11.0, *) { return biometryType() == .touchID // return biometryType() == .typeTouchID for Xcode 9.1 } let context = LAContext() return context.canEvaluatePolicy(biometricsAuthPolicy, error: nil) } @objc @available(iOS 11.0, *) func biometryType() -> LABiometryType { var error: NSError? let context = LAContext() guard context.canEvaluatePolicy(biometricsAuthPolicy, error: &error) else { if #available(iOS 11.2, *) { return .none } return LABiometryType.LABiometryNone // return LABiometryType.none for Xcode 9.1 } return context.biometryType } 功能

更新帖子

trim ()