How to write a simple query or PL/SQL code in Oracle to check if order_id exists in one table before processing another table?
I am looking to populate a table with some data and normally I would run some insert scripts or upload via a csv file. The requirements I have is that the data can only be populated in the 2nd table as long as the order_id is within the orders table. From what I know I probably need to write some PL/SQL code to check if the order_id exists in the orders table before running the insert scripts but not sure how to write this. I would appreciate it if somebody could get me started. This is the create statement for the Orders Table: CREATE TABLE ORDERS ( ORDER_ID NUMBER NOT NULL, STATUS VARCHAR2(9) NOT NULL, ORDER_DATE DATE NOT NULL, PRIMARY KEY(ORDER_ID), CONSTRAINT CHK_STATUS CHECK (STATUS = 'OPEN' OR STATUS = 'CLOSED') ); The create statement for the 2nd table is: CREATE TABLE ORDER2 ( ORDER_ID NUMBER NOT NULL, PRODUCT_ID NUMBER NOT NULL, ORDER_DATE DATE NOT NULL, PRIMARY KEY(PRODUCT_ID) ); Thanks. by Michael Owen ...