如何执行自定义MySQL列格式 [英] How to enforce custom MySQL column format
问题描述
如果我想在MySQL中定义自定义列格式怎么办?我想要的自定义格式始终是2位整数,然后是#号,然后是一个空格,然后是一个十进制数字,该数字在小数点后两位.允许值的示例如下:
What if I wanted to define a custom column format in MySQL? The custom format that I want is always a 2 digit integer, followed by the # sign, then a space, then a decimal number with 2 digits after the decimal. Examples of allowed values are like this:
30# 11.00
27# 17.25
40# 17.25
不允许的值是这样的:
30# 11
40# 20.5
some string
在MySQL中这可能吗?如果是这样,那么有关如何执行操作的任何提示?
Is this possible in MySQL? If so, any hints on how to do it?
推荐答案
好吧,因为"CHECK子句已被解析,但被所有存储引擎忽略."在mysql中,您唯一剩下的选择是将表上的插入/更新之前触发器添加到 regexp 您的输入并继续.
well since "The CHECK clause is parsed but ignored by all storage engines." in mysql, your only remaining option would be to add a before insert/update trigger on your table to regexp your input and proceed.
这篇关于如何执行自定义MySQL列格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!