Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:15:43+00:00 2026-06-16T05:15:43+00:00

I am trying to create a trigger to calculate a derived attribute on each

  • 0

I am trying to create a trigger to calculate a derived attribute on each insert command. However I am getting compilation errors, I dont know where is the problem.

CREATE OR REPLACE TRIGGER NewTrigger 
BEFORE INSERT 
ON Dates FOR EACH ROW 
 BEGIN 
   SET :NEW.difference := :NEW.date1 - :NEW.date2; 
 END;

Show errors shows me this information:

LINE/COL ERROR
-------- -----------------------------------------------------------------
1/7  PL/SQL: SQL Statement ignored
1/11     PL/SQL: ORA-00922: missing or invalid option
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:15:44+00:00Added an answer on June 16, 2026 at 5:15 am

    It’s not the trigger, it’s the data type. If you substract a date from another date, the result is an interval, not another date:

    CREATE TABLE dates (date1 DATE, date2 DATE, datediff DATE, numdiff NUMBER);
    INSERT INTO dates (date1, date2) VALUES (sysdate, sysdate-1);
    
    UPDATE dates SET numdiff = date1 - date2;
    1 rows updated
    
    UPDATE dates SET datediff = date1 - date2;
    SQL Error: ORA-00932: inconsistent datatypes: expected DATE got DATE JULIAN
    

    So, if the trigger stores the interval in a number, it compiles:

    CREATE OR REPLACE TRIGGER newtriggernum
      BEFORE INSERT ON dates FOR EACH ROW
    BEGIN
      :new.numdiff := :new.date1 - :new.date2;
    END;
    /
    TRIGGER NEWTRIGGERNUM compiled
    

    and if it stores the interval in a date, it doesn’t:

    CREATE OR REPLACE TRIGGER newtriggerdate
      BEFORE INSERT ON dates FOR EACH ROW
    BEGIN
      :new.datediff := :new.date1 - :new.date2;
    END;
    /
    Error(2,11): PL/SQL: ORA-00922: missing or invalid option
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a trigger but is having errors.... SQL> CREATE OR
I'm trying the following : CREATE TRIGGER checkgrade ON [Homework4part3].[dbo].[Enrollment] FOR INSERT AS IF
I'm trying to create a trigger that will do the following. After insert on
I am trying to create a trigger in Oracle. I know sql but i
Hi i'm trying to create below trigger CREATE TRIGGER TRIGBEFORE INSERT ON employee FOR
I am trying to create a trigger wherein it will insert a new row
I'm trying to create a simple Before Insert MySQL Trigger, to check if any
I'm new to SQL and I'm trying to create a trigger that would insert
I am trying to create a BEFORE INSERT trigger that will check the incoming
Hello all I am trying to create an in instead of insert trigger which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.