ORA-01843:不是检查约束的有效月份

时间:2022-04-25 22:24:16

I'm trying to put a Check constraint on a born date in a range of date time because I don't want to let the user insert a value < of 01-JAN-1900.

我试图在一个日期时间范围内对出生日期设置Check约束,因为我不想让用户插入值<01-JAN-1900。

I'm trying to elabourate this as :

我试图将其阐述为:

CONSTRAINT  BORN_VALIDITY   CHECK(BORN_DATE > TO_DATE('01-GEN-1900','DD-MON-1900'));

I also altered the date format session in the beginning with

我还在一开始就改变了日期格式会话

ALTER SESSION NSL_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';

but I'm receiving the same error with no pity from Oracle SQL.

但我收到同样的错误,没有来自Oracle SQL的遗憾。

There is some other way to set a date range on my check constraint?

还有其他方法可以在我的检查约束上设置日期范围吗?

1 个解决方案

#1


2  

Assuming that the language of your DB is Italian, or whatever language in which you can write January as GEN, you should use TO_DATE('01-GEN-1900','DD-MON-YYYY').

假设您的数据库的语言是意大利语,或者您可以将1月份作为GEN编写的任何语言,您应该使用TO_DATE('01 -GEN-1900','DD-MON-YYYY')。

To have a solution that works no matter the language, you could better use the ANSI standard date '1900-01-01'

要获得无论语言有效的解决方案,您都可以更好地使用ANSI标准日期'1900-01-01'

#1


2  

Assuming that the language of your DB is Italian, or whatever language in which you can write January as GEN, you should use TO_DATE('01-GEN-1900','DD-MON-YYYY').

假设您的数据库的语言是意大利语,或者您可以将1月份作为GEN编写的任何语言,您应该使用TO_DATE('01 -GEN-1900','DD-MON-YYYY')。

To have a solution that works no matter the language, you could better use the ANSI standard date '1900-01-01'

要获得无论语言有效的解决方案,您都可以更好地使用ANSI标准日期'1900-01-01'