开发者

Oracle varchar2 minimum length

In Oracle db we have a table with varchar2 type of column (for example USERNAME). How can I set a exact (or 开发者_如何学Cat least minimum) length for this column? So that all usernames inserted into this table can be only 10 (or have to be at least 10) characters long.


You could use a check constraint:

CREATE TABLE mytable (
  mycolumn varchar2(50),
  constraint strlen check (length(mycolumn) > 2)
)

Or something similar. I'm not sure how performant this is, though.


Or just for fun,

CREATE TABLE testit
( mycolumn VARCHAR2(20) CONSTRAINT min_length_chk CHECK (mycolumn LIKE '__%') );

It's less explicit than the LENGTH() approach though so I'm not sure I'm recommending it except as an idea for related issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜