Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

ORA-02438: Column check constraint cannot reference other columns

SmithJohn45May 27 2024 — edited May 27 2024

i am trying this on apex.oracle.com

i followed the topic on stackoverflow:

https://stackoverflow.com/questions/49749775/ora-02438-column-check-constraint-cannot-reference-other-columns

i tried to create a table as below to test this constraint:

create table temp_loan (
    id number,
    emp_id number not null,
    date_from date not null,
    date_to   date not null,
    loan_amount number,
    loan_status varchar2(1) default 'A' check(loan_status in ('Y', 'N')),
    remarks   varchar2(200),
    constraint check (date_from <= date_to)
);

but it is throwing error: ORA-02438: Column check constraint cannot reference other columns.

in above link, they showed that the table with constraint (table level) has been created, but mine is showing error.

is anything i am doing wrong or missing something or i mis-understood it completely?

during my search, some people showed that you can do it in a trigger, it is ok.

please help.

regards

This post has been answered by Lothar Armbrüster on May 27 2024
Jump to Answer

Comments

Post Details

Added on May 27 2024
10 comments
236 views