Skip to Main Content

Oracle Forms

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!

Trigger To Insert Into Two Tables

905669Dec 15 2011 — edited Dec 18 2011
Hello all. I am trying to create a trigger that will insert information into one of two tables in my database. They tables are subtypes of a supertype table and therefore a form cannot be created within Oracle Apex as there is no primary key column.

I have a Menu table in which I want users to be able to add new Menus for a restaurant but also... When the create button is clicked, the record should be inserted into either of the subtype tables Past_Menus ore Present_Menus

The problem is... I cannot figure out how to write a trigger to do so correctly. In order to determine which record is inserted into which table the Menu_Date will be used as the condition.

Can anyone help me write a trigger to do this?

Here is the SQL code

CREATE TABLE tblMENUS (
MENU_NO NUMBER NOT NULL,
MENU_NAME VARCHAR2(30),
STORE_ID NUMBER,
CONSTRAINT PK_MENU PRIMARY KEY (MENU_NO));

CREATE TABLE tblPAST_MENUS (
MENU_NO NUMBER NOT NULL,
MENU_DATE DATE,
RATING CHAR(5));

CREATE TABLE tblPRESENT_MENUS (
MENU_NO NUMBER NOT NULL,
ACTIVITY CHAR(12));

---------------------TRIGGER I ATTEMPTED TO WRITE --------------------------

create or replace trigger "SENDTOMENU"
BEFORE
insert or update or delete on "TBLMENUS"
for each row
begin
IF (MENU_DATE < 01/12/11) THEN
INSERT INTO TBLPAST_MENUS(MENU_NO, MENU_DATE, RATING)
VALUES(:NEW.MENU_NO, :OLD.MENU_DATE, :NEW.RATING)
ELSE
INSERT INTO TBLPRESENT_MENUS(MENU_NO, MENU_DATE, ACTIVITY)
VALUES(:NEW.MENU_NO, :NEW.MENU_DATE, :NEW.ACTIVITY)
END IF;
end;

Thanks for your help.

Grant Doole.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2012
Added on Dec 15 2011
6 comments
3,846 views