简体   繁体   English

MariaDB 中的 INITCAP

[英]INITCAP in MariaDB

I am currently trying to check that every values that are inserted into my MariaDB table the 1st letter of every word in uppercase, so I tried to use CONSTRAINT nombreok CHECK (INITCAP(nombre_director) = nombre_director));我目前正在尝试检查插入到我的 MariaDB 表中的每个值是否为大写的每个单词的第一个字母,因此我尝试使用CONSTRAINT nombreok CHECK (INITCAP(nombre_director) = nombre_director)); but it doesn't works because it gives me an error saying that function INITCAP() cannot be used in a CHECK... what can I do to solve it?但它不起作用,因为它给了我一个错误,说函数 INITCAP() 不能在 CHECK 中使用......我能做些什么来解决它?

I think initcap() is not deterministic because the results may depend on the default collation of the database (under some circumstances).我认为initcap()不是确定性的,因为结果可能取决于数据库的默认排序规则(在某些情况下)。

You can ensure that the first characters are capitalized using:您可以使用以下方法确保第一个字符大写:

CONSTRAINT nombreok CHECK (not (nombre_director collate latin1_general_cs) REGEXP '(^|[[:space:]])[[:lower:]]')

Here is a db<>fiddle. 是一个 db<>fiddle。

If you want to check the lower case as well:如果您还想检查小写:

CONSTRAINT nombreok CHECK ((nombre_director collate latin1_general_cs) REGEXP '^([[:upper:]][[:lower:]]+([[:space:]]+|$))+$')

However, you might want to extend this beyond just alphabetical characters.但是,您可能希望将其扩展到不仅仅是字母字符。

Here is a db<>fiddle for this. 是一个 db<>fiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM