列的最小长度限制 [英] Minimum length constraint on a column
问题描述
我正在尝试在Oracle中实现最小长度限制.
I'm trying to implement a minimum length constraint in Oracle.
As I read in this answer and multiple other similar questions I tried:
ALTER TABLE my_table
ADD CONSTRAINT MY_TABLE_PASSWORD_CK CHECK (DATALENGTH(password) >=4)
我正在得到"DATALENGTH": invalid identifier"
.我也尝试过:
And I am getting "DATALENGTH": invalid identifier"
. I also tried:
( DATALENGTH([password]) >=4 )
( LEN([password]) >=4 )
( LEN(password) >=4 )
Oracle中此检查约束的当前格式是什么?
What is the current format for this check constraint in Oracle?
推荐答案
DATALENGTH()
返回 SQL Server 中的字节长度.等效的Oracle函数是LENGTHB()
(在此处 ):
DATALENGTH()
returns the length in bytes in SQL Server. The equivalent Oracle function is LENGTHB()
(documented here):
ALTER TABLE my_table
ADD CONSTRAINT MY_TABLE_PASSWORD_CK CHECK (LENGTHB(password) >= 4)
但是,出于您的目的,我认为字符串长度在两个数据库中都是合适的,在Oracle中是LENGTH()
(在SQL Server中是LEN()
).
However, for your purposes, I think the string length would be appropriate in both databases, LENGTH()
in Oracle (or LEN()
in SQL Server).
这篇关于列的最小长度限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!