Skip to content
Advertisement

SQL – Column string characters has to be greater than 25

When creating a table, can you put a constraint check on a column to check that the string value has to be greater than 25 characters? I know it can be done on numeric, but having difficulty to do it for a string.

Here is my code:

I realize this only checks to see if the numeric value is greater than 25, but how can make it that it checks that the string value is greater than 25 characters

Advertisement

Answer

In Oracle, the maximum length of a string in a table is 4000 8-bit characters (as explained here). And you generally use varchar2() for variable length strings. So you can do:

If you want an unlimited length string, you can use a CLOB, but those are generally a bit more finicky to work with.

If you happen to be using SQL Server (which your syntax suggests), then this would be:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement