列的最小长度限制 [英] Minimum length constraint on a column

查看:91
本文介绍了列的最小长度限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆