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

  • SEARCH
  • Home
  • 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 8629349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:46:54+00:00 2026-06-12T08:46:54+00:00

First and foremost, this is for an assignment, so most of the really cool

  • 0

First and foremost, this is for an assignment, so most of the really cool pre-written functions you’ll want to suggest, I will not be allowed to use.

I have a couple tables that all have fields

creation_date
created_by
last_update_date
last_updated_by

I need to write a trigger that fills these in for creation or updating. The problem is, these tables have null values that are problematic to me. Example:

CREATE TABLE parts
(
pno                NUMBER,
pname              VARCHAR2(50) NOT NULL,
qoh                NUMBER       NOT NULL,
price              NUMBER(5,2),
reorder_level      NUMBER(2),
creation_date      DATE         NOT NULL,
created_by         VARCHAR2(10) NOT NULL,
last_update_date   DATE         NOT NULL,
last_updated_by    VARCHAR2(10) NOT NULL,
CONSTRAINT parts_PK PRIMARY KEY (pno))

These NOT NULL’s are given to me and I’m not allowed to change them. So I’m having trouble conceptualizing this.

  • If my trigger adds these values before the field is created, I can’t do an INSERT INTO with those fields blank because they’re NOT NULL.
  • If my trigger adds these values after the field is created, I get compilation errors ORA-00903 and 00922. Invalid table name and invalid option.

I was thinking my trigger would look like

CREATE OR REPLACE TRIGGER pcreate
  BEFORE UPDATE on parts
  FOR EACH ROW
BEGIN
  UPDATE
    SET creation_date = SYSDATE;
    SET created_by = USER;
    SET last_update_date = SYSDATE;
    SET last_updated_by = USER;
END;
/

CREATE OR REPLACE TRIGGER pchange
  BEFORE UPDATE on parts
  FOR EACH ROW
BEGIN
  UPDATE
    SET last_update_date = SYSDATE;
    SET last_updated_by = USER;
END;
/
repeat for the other tables

I might be allowed to use UPSERT but I don’t really know how that works.. Any suggestions are welcome. I’m really in this to learn so any other advice is appreciated.

EDIT:

My package that will not acknowledge the trigger is as follows. Do I need to call the trigger inside the package?

CREATE OR REPLACE PACKAGE process_orders 
AS
  PROCEDURE add_order (p_cno IN NUMBER, p_eno IN NUMBER, p_received IN DATE);
  PROCEDURE add_order_details (p_ono IN NUMBER, p_pno IN NUMBER, p_qty IN NUMBER);
  PROCEDURE ship_order (p_ono IN NUMBER, p_sdate IN DATE);
  PROCEDURE delete_order (p_ono IN NUMBER);
  FUNCTION total_emp_sales (f_eno IN NUMBER) RETURN NUMBER;
END process_orders;
/

CREATE OR REPLACE PACKAGE BODY process_orders 
AS
  PROCEDURE add_order (p_cno IN NUMBER, p_eno IN NUMBER, p_received IN DATE) 
  IS
  ao_emsg       VARCHAR2(100);
  p_rec_today   DATE;
  BEGIN
    SELECT SYSDATE INTO p_rec_today FROM dual;
    IF p_received is null THEN
        INSERT INTO orders (ono, cno, eno, received)
        VALUES(order_number_seq.NEXTVAL,p_cno,p_eno,p_rec_today);
    ELSE
        INSERT INTO orders (ono, cno, eno, received)
    VALUES(order_number_seq.NEXTVAL,p_cno,p_eno,p_received);
    END IF;

  EXCEPTION
    WHEN OTHERS THEN
      ao_emsg := substr(SQLERRM,1,100);
      INSERT INTO orders_errors (ono,transaction_date,message)
      VALUES(order_number_seq.CURRVAL,SYSDATE,ao_emsg);
  END;
  --Etc. Procedures
END;
/
  • 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-12T08:46:56+00:00Added an answer on June 12, 2026 at 8:46 am

    In your trigger, you simply want to modify the :new record. Your triggers would look something like

    CREATE OR REPLACE TRIGGER parts_before_insert
      BEFORE INSERT on parts
      FOR EACH ROW
    BEGIN
      :new.creation_date := SYSDATE;
      :new.created_by := USER;
      :new.last_update_date := SYSDATE;
      :new.last_updated_by := USER;
    END;
    

    and

    CREATE OR REPLACE TRIGGER parts_before_update
      BEFORE UPDATE on parts
      FOR EACH ROW
    BEGIN
      :new.last_update_date := SYSDATE;
      :new.last_updated_by := USER;
    END;
    

    In your INSERT statement, you would omit these four columns and let the trigger fill in the values. For example (obviously, your primary keys would be coming from something like a sequence rather than being hard-coded)

    SQL>  insert into parts( pno, pname, qoh, price, reorder_level )
      2     values( 1, 'Widget', 10, 100, 75 );
    
    1 row created.
    
    SQL> select *
      2    from parts;
    
           PNO PNAME                                                     QOH
    ---------- -------------------------------------------------- ----------
         PRICE REORDER_LEVEL CREATION_ CREATED_BY LAST_UPDA LAST_UPDAT
    ---------- ------------- --------- ---------- --------- ----------
             1 Widget                                                     10
           100            75 26-SEP-12 SCOTT      26-SEP-12 SCOTT
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First and foremost, I have tried searching and can't really find anything that will
First and foremost: JSON and XML are not an option in this specific case,
First and foremost, thank you all for reading this and helping, I'm very grateful.
This is more like general knowledge to understanding Android Market. So, first and foremost,
First and foremost, I do not know RegEx but am trying to piece something
First and foremost, I'm so sorry about how long this question is and appreciate
First and foremost, apologies for any cross-posting. Hope I'm not repeating an issue here,
OK first and foremost, performance is most important here so I doubt a map
Please no jQuery code, as I want to learn javascript first and foremost. I
First and foremost, I apologize for any vagueness in this question. At this point,

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.