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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:37:23+00:00 2026-06-16T06:37:23+00:00

I am attempting to write this trigger but it is not working right. I

  • 0

I am attempting to write this trigger but it is not working right. I have a table GIVING(donor, receiver, giftname) and a table PERSONS(pname, age, haircolor). for the trigger I want it to spit out a message whenever the donor and receiver have the same hair color. Trivial, I know, but I’m just starting to learn triggers and am totally stuck on why this won’t work. Thanks.

create or replace TRIGGER SameHairColor
BEFORE INSERT OR UPDATE OF GIFTNAME ON GIVING
DECLARE
  haircolordonor varchar(255);
  haircolorreceiver varchar(255);
BEGIN
select persons.haircolor into haircolordonor
from persons, giving
where (donor = persons.pname);
select persons.haircolor into haircolorreceiver
from persons, giving
where (receiver = persons.pname);

if (haircolordonor = haircolorreceiver) then

dbms_output.put_line('Wow, they have the same haircolor!  Who would have thought?');
end if;

end;

The error message I get is error during execution “exact fetch returns more than requested number of rows”, pointing to the row below DECLARE…?

  • 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-16T06:37:24+00:00Added an answer on June 16, 2026 at 6:37 am

    You are not restricting your queries to the donor/receiver of the inserted/updated row. They should look like this:

    select persons.haircolor
    into haircolordonor
    from persons
    where persons.pname = :NEW.donor;
    

    BTW: Your trigger only fires on INSERT OR UPDATE OF GIFTNAME, while it should fire on INSERT OR UPDATE OF donor, receiver and you need to use FOR EACH ROW.

    Your trigger should look like this:

    CREATE OR REPLACE TRIGGER SameHairColor
    BEFORE INSERT OR UPDATE OF donor, receiver ON GIVING
      FOR EACH ROW
    DECLARE
      haircolordonor varchar(255);
      haircolorreceiver varchar(255);
    BEGIN
      select persons.haircolor into haircolordonor
      from persons
      where (persons.pname = :NEW.donor);
      select persons.haircolor into haircolorreceiver
      from persons
      where (persons.pname = :NEW.receiver);
    
      IF (haircolordonor = haircolorreceiver) THEN
        dbms_output.put_line('Wow, they have the same haircolor!  Who would have thought?');
      END IF;
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to write to a logfile, but File.Write(path, string) is not giving me
I am attempting to re-write this bash function in C, but the a little
I attempting to write a simple JQuery search. This is what I have so
I can't seem to get this working. So I'm attempting to write a script
I have been attempting to write a VBA Script that can parse out other
I am attempting to write my first Dynamics Crm 2011 plugin. I have therefore
I am attempting to write this html in haml so as to add an
I'm attempting to write my first unity script. This is the code for a
I'm attempting to write a particular script that logs into a website. This specific
Is this possible? I am attempting to write a function for onmousedown that will

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.