Search code examples
sqloraclecheck-constraints

Oracle sql Check constraint on date field


I want to add a check constraint that compares columnA with year data(format: 2020) to columnB with date data (format: 20200929):

columnA=SUBSTR(columnB,1,4) should be my check constraint.

But need to specify the date format for column B. How can I do that? Please help. Thank you!


Solution

  • If you want them to be the same, then use:

    check (columnA = extract(year from columnb))