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!

Check Constraint based off two Tables

Dj SteeleMar 12 2018 — edited Mar 14 2018

Good Day Community,

I'm using Oracle 12c DB and APEX Application Express 5.1.4.00.08

I would like to Create a Check Constraint;    where the Check would be the Return Date has to be <= to Sale_Date;  with Logic that you can not have a Return Date that  has a Date Greater Than the Sale_Date

Based off two Tables Below:

CREATE TABLE  "BB_PROD_SALES"

   ( "IDPRODUCT" NUMBER(4,0)  GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),

"SALE_DATE" DATE NOT NULL,

        "PRICE" NUMBER (6,2) NOT NULL,

"QTY" NUMBER(5,0) NOT NULL,

"TOTAL" NUMBER (6,2) GENERATED ALWAYS AS ("PRICE" * "QTY") VIRTUAL,

Constraint pk_IDPRODUCT_BB_PROD_SALES PRIMARY KEY (IDPRODUCT)

   );

/

AND

CREATE TABLE BB_PROD_RET

     (

      "IDPRODUCT" NUMBER (4,0),

      "SALE_DATE" DATE NOT NULL,

      "PRICE" NUMBER (6,2) NOT NULL,

      "QTY" NUMBER(5,0) NOT NULL,

      "TOTAL" NUMBER (6,2) NOT NULL,

      "RETURN_DATE" DATE NOT NULL,

    

Constraint fk_IDPRODUCT_BB_PROD_RET FOREIGN KEY (IDPRODUCT)

    REFERENCES BB_PROD_SALES (IDPRODUCT)

    );

/

Thanks in Advance,

DSteele41

This post has been answered by Paulzip on Mar 12 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 9 2018
Added on Mar 12 2018
6 comments
1,337 views