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 7916917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:58:42+00:00 2026-06-03T14:58:42+00:00

I have the following tables: FACULTY table CREATE TABLE FACULTY ( FACULTY_ID NUMBER(3,0), FACULTY_NAME

  • 0

I have the following tables:

FACULTY table

CREATE TABLE  "FACULTY" 
   (    "FACULTY_ID" NUMBER(3,0), 
    "FACULTY_NAME" VARCHAR2(30), 
    "FACULTY_DEAN" VARCHAR2(30), 
     CONSTRAINT "FACULTY_PK" PRIMARY KEY ("FACULTY_ID") ENABLE
   )

COURSE table

CREATE TABLE  "COURSE" 
   (    "COURSE_ID" NUMBER(5,0), 
    "COURSE_NAME" VARCHAR2(50), 
    "COURSE_LEVEL" NUMBER, 
    "FACULTY" NUMBER, 
     CONSTRAINT "COURSE_PK" PRIMARY KEY ("COURSE_ID") ENABLE
   )

so now i want to achieve two things

(1) when a faculty_id is updated on the faculty table. a trigger will fire and update the corresponding rows in the course table with new faculty_id. it will also store the old faculty_id value, name of course, and the date in which the operation is performed in a course_log table.

Below is what I got

create or replace trigger update_faculty
after update on faculty
for each row
begin
   insert into course_log 
     values (:old.faculty_id, 
             (select course_name 
                from course 
               where faculty=:old.faculty_id),
             sysdate);
   update course 
      set faculty=:new.faculty_id 
    where faculty=:old.faculty_id;
end;

But I get the following error.

error ORA-01427: single-row subquery returns more than one row ORA-06512: at “SYSTEM.UPDATE_FACULTY”, line 2 ORA-04088: error during execution of trigger ‘SYSTEM.UPDATE_FACULTY’

any ideas on how to solve it?

(2) Write a trigger that fires when try change the course_id attribute in the course table, which will check whether the value already exists in the course table and will update successfully if it is a new value. If the value already exists in any row, the trigger will throw an application error saying “The course_id already exists! Update not successful.”

below is my query

CREATE OR REPLACE TRIGGER  "UPDATE_COURSE_ID" 
after update on course
for each row
declare 
    error number;
begin
    select count(*) 
      into error 
    from course
    where course_id=:new.course_id;

    if error > 0 then
        raise_application_error (-20000,'The course_id already found! Update not success'); 
    end if;
    if error = 0 then
        update course set course_id=:new.course_id where course_id=:old.course_id;
    end if;
end;

But I got this error

error ORA-04091: table SYSTEM.COURSE is mutating, trigger/function may not see it ORA-06512: at “SYSTEM.UPDATE_COURSE_ID”, line 5 ORA-04088: error during execution of trigger ‘SYSTEM.UPDATE_COURSE_ID’

  • 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-03T14:58:44+00:00Added an answer on June 3, 2026 at 2:58 pm

    For the first question, since you may want to insert multiple rows into the course_log table, you’d need to do something like

    create or replace trigger update_faculty
      after update on faculty
      for each row
    begin
       -- I'm guessing about the definition of the course_log table
       insert into course_log( faculty_id, course_name, log_date ) 
         select :old.faculty_id, course_name, sysdate
           from course 
          where faculty=:old.faculty_id;
    
       update course 
          set faculty=:new.faculty_id 
        where faculty=:old.faculty_id;
    end;
    

    For the second question, it doesn’t make sense to use a trigger. You’d want to use a constraint. And you already have a primary key constraint on course_id in course which is already preventing duplicate course_id values.

    Enforcing this sort of thing with triggers is a really poor idea. Since a row level trigger on course cannot query the course table (with the exception of a row-level insert trigger if your insert statements are always of the single-row form INSERT ... VALUES or triggers that use autonomous transactions, neither of which is appropriate here). So if you really wanted to do this with triggers, you’d need to create a package that contained a collection of course_id values, a before statement trigger that initializes the collection, a row-level trigger that adds the :new.course_id to the collection, and an after statement trigger that iterates over the collection and looks for duplicate course_id values. That’s a lot of objects to do something that shouldn’t be done with triggers in the first place and that is already being done by your constraint. If you’re just learning about triggers, I’m guessing that you haven’t been taught about packages or collections yet which makes the solution even less appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: CREATE TABLE Faculty ( FacSSN text(9) primary key, FacFirstName
I have the following tables CREATE TABLE `files` ( `fileid` int(11) NOT NULL AUTO_INCREMENT,
I have the following tables: CREATE TABLE title ( booktitle VARCHAR( 60 ), title_id
I have following tables: Profiles: ProfileID (Primary Key) ProfileName, etc. Contacts: ContactID (Primary Key)
I have following tables: CREATE TABLE IF NOT EXISTS stats ( date date NOT
I'm using EF v1. I have following tables: CREATE TABLE category ( category_id int
i have following 3 tables CREATE TABLE [dbo].[dspartner]( [dspartnerid] [bigint] IDENTITY(1,1) NOT NULL, [name]
I have the following tables: Persons, Person_Categories and Persons_PersonCategories which is a linking table
I have the following tables Client Table and Product Table ID Name ClientProduct Table
I have following tables in my database: SuggestionsLog Table: ID, Title, Description. Employee Table:

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.