SQL 列的最小长度约束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32156650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Minimum length constraint on a column
提问by Alexandru Severin
I'm trying to implement a minimum length constraint in Oracle.
我正在尝试在 Oracle 中实现最小长度约束。
As I read in thisanswer and multiple other similar questions I tried:
当我在这个答案和其他多个类似问题中读到时,我尝试了:
ALTER TABLE my_table
ADD CONSTRAINT MY_TABLE_PASSWORD_CK CHECK (DATALENGTH(password) >=4)
And I am getting "DATALENGTH": invalid identifier"
. I also tried:
我得到"DATALENGTH": invalid identifier"
. 我也试过:
( DATALENGTH([password]) >=4 )
( LEN([password]) >=4 )
( LEN(password) >=4 )
What is the current format for this check constraint in Oracle?
Oracle 中此检查约束的当前格式是什么?
回答by Gordon Linoff
DATALENGTH()
returns the length in bytes in SQL Server. The equivalent Oracle function is LENGTHB()
(documented here):
DATALENGTH()
返回SQL Server中的字节长度。等效的 Oracle 函数是LENGTHB()
(在此处记录):
ALTER TABLE my_table
ADD CONSTRAINT MY_TABLE_PASSWORD_CK CHECK (LENGTHB(password) >= 4)
However, for your purposes, I think the string length would be appropriate in both databases, LENGTH()
in Oracle (or LEN()
in SQL Server).
但是,出于您的目的,我认为字符串长度LENGTH()
在 Oracle(或LEN()
SQL Server)中的两个数据库中都是合适的。