Minimum length constraint on a column
33,411
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)
However, for your purposes, I think the string length would be appropriate in both databases, LENGTH()
in Oracle (or LEN()
in SQL Server).
Author by
Alexandru Severin
Updated on August 04, 2022Comments
-
Alexandru Severin almost 2 years
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)
And I am getting
"DATALENGTH": invalid identifier"
. I also tried:( DATALENGTH([password]) >=4 ) ( LEN([password]) >=4 ) ( LEN(password) >=4 )
What is the current format for this check constraint in Oracle?