首页 > 解决方案 > MariaDB 约束中的 INITCAP

问题描述

我目前正在尝试在 MariaDB 中创建一个约束,检查每个空格后是否有一个大写字母(只是为了检查人名的正确格式)并且我尝试过使用 INITCAP 但它不允许我在检查中执行. 你能帮我做吗?

pepe Antonio -> It shouldn't go in
Pepe antonio -> It shouldn't go in
Pepe Antonio -> It should go in

标签: mysqlsqldatabasemariadbconstraints

解决方案


您可以使用:

name not regexp binary '(^| )[[:lower:]]'

是一个 db<>fiddle。

binary是因为较新版本的 MariaDB 具有不区分大小写的正则表达式匹配。而且您显然很关心案例。

这是如何运作的:

'(^| )[[:lower:]]'
--^ beginning of string
----^ space
-----^ expression has either one
------^ followed by a lower-case character

当然,这是你不想要的。因此,NOT REGEXP.


推荐阅读