Solved

ORA-01422 on-insert trigger

Posted on 2004-10-14
11
11,798 Views
Last Modified: 2007-12-19
I am getting a ORA-01422 error which is Fetch returns more than one row.
How can I be getting this error on an insert or update trigger?
0
Comment
Question by:uTab
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 23

Expert Comment

by:seazodiac
ID: 12308511
Post the trigger body, so that people can help you...

but the error means that your query return more than one row...
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12308538
this kind of error is generally due to doing a SELECT x INTO var ...
which expects only a single row to be returned by the SELECT statement, but there is actually multiple rows.

can you post some code - not enough information to go by..
0
 
LVL 9

Expert Comment

by:konektor
ID: 12309019
check the body of trigger for all select ... into ... and all triggers of all inserts  which is in your trigger
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:uTab
ID: 12309357
Here is the code.

BEGIN
      DECLARE
            duplicate_info EXCEPTION;
            PRAGMA EXCEPTION_INIT (duplicate_info, -00001);
      BEGIN
            INSERT INTO DBCONTACTS
                  (CONTACTID,
                  COMPANYNAME,
                  TAXID,
                  INACTIVEFLAG,
                  PENDINGFLAG,
                  AVAILTIMESTART,
                  AVAILTIMEEND,
                  DONTCALL,
                  WEBPAGE,
                  LASTINQUIRY,
                  DATELASTINQ,
                  PERMGRANTED,
                  COMMENTFIELD,
                  PROSPECTFLAG)
            VALUES
                  (:CONTACTS.CONTACTID,
                  :CONTACTS.COMPANYNAME,
                  :CONTACTS.TAXID,
                  'N',
                  'N',
                  :CONTACTS.AVAILTIMESTART,
                  :CONTACTS.AVAILTIMEEND,
                  :CONTACTS.DONTCALL,
                  :CONTACTS.WEBPAGE,
                  :CONTACTS.LASTINQUIRY,
                  :CONTACTS.DATELASTINQ,
                  :CONTACTS.PERMGRANTED,
                  :CONTACTS.COMMENTFIELD,
                  'Y');
            EXCEPTION
               WHEN dup_val_on_index THEN
                     UPDATE DBCONTACTS
                           SET CONTACTID                        = :CONTACTS.CONTACTID,
                                          COMPANYNAME                  = :CONTACTS.COMPANYNAME,
                                          TAXID                                    = :CONTACTS.TAXID,
                                          INACTIVEFLAG            = :CONTACTS.INACTIVEFLAG,
                                          PENDINGFLAG                  = :CONTACTS.PENDINGFLAG,
                                          AVAILTIMESTART      = :CONTACTS.AVAILTIMESTART,
                                          AVAILTIMEEND            = :CONTACTS.AVAILTIMEEND,
                                          DONTCALL                        = :CONTACTS.DONTCALL,
                                          WEBPAGE                              = :CONTACTS.WEBPAGE,
                                          LASTINQUIRY                  = :CONTACTS.LASTINQUIRY,
                                          DATELASTINQ                  = :CONTACTS.DATELASTINQ,
                                          PERMGRANTED                  = :CONTACTS.PERMGRANTED,
                                          COMMENTFIELD            = :CONTACTS.COMMENTFIELD,
                                          PROSPECTFLAG            = :CONTACTS.PROSPECTFLAG
                              WHERE CONTACTID = :CONTACTS.CONTACTID;
            END;
      DECLARE
            duplicate_info EXCEPTION;
            PRAGMA EXCEPTION_INIT (duplicate_info, -00001);
      BEGIN
      INSERT INTO DBCONTACTPERSON
            (contactid,
        contacttype,
        taxid,
            prefix,
            firstname,
            middlename,
            lastname,
            suffix,
            address1,
            address2,
            city,
            state,
            zipcode,
            workphone,
            homephone,
            faxnumber,
            birthdate,
            maritalstatus,
            denomid,
            citizen,
            emailaddress)
      VALUES
            (:CONTACTS.contactid,
        'P',
        :CONTACTS.taxid,
            :CONTACTS.P_prefix,
            :CONTACTS.P_firstname,
            :CONTACTS.P_middlename,
            :CONTACTS.P_lastname,
            :CONTACTS.P_suffix,
            :CONTACTS.P_address1,
            :CONTACTS.P_address2,
            :CONTACTS.P_city,
            :CONTACTS.P_state,
            :CONTACTS.P_zipcode,
            :CONTACTS.P_workphone,
            :CONTACTS.P_homephone,
            :CONTACTS.P_faxnumber,
            :CONTACTS.P_birthdate,
            :CONTACTS.P_maritalstatus,
            :CONTACTS.P_denomid,
            :CONTACTS.P_citizen,
            :CONTACTS.P_emailaddress);
      EXCEPTION
               WHEN dup_val_on_index THEN
                     UPDATE DBCONTACTPERSON
                           SET      taxid                        = :CONTACTS.TAXID,
                                          prefix                  = :CONTACTS.P_PREFIX,                  
                                          firstname            = :CONTACTS.P_FIRSTNAME,
                                          middlename      = :CONTACTS.P_MIDDLENAME,
                                          lastname            = :CONTACTS.P_LASTNAME,
                                          suffix                  = :CONTACTS.P_SUFFIX,
                                          address1            = :CONTACTS.P_ADDRESS1,
                                          address2            = :CONTACTS.P_ADDRESS2,
                                          city                        = :CONTACTS.P_CITY,
                                          state                        = :CONTACTS.P_STATE,
                                          zipcode                  = :CONTACTS.P_ZIPCODE,
                                          workphone            = :CONTACTS.P_WORKPHONE,
                                          homephone            = :CONTACTS.P_HOMEPHONE,
                                          faxnumber            = :CONTACTS.P_FAXNUMBER,
                                          birthdate            = :CONTACTS.P_BIRTHDATE,
                                          maritalstatus      = :CONTACTS.P_MARITALSTATUS,
                                          denomid                  = :CONTACTS.P_DENOMID,
                                          citizen                  = :CONTACTS.P_CITIZEN,
                                          emailaddress      = :CONTACTS.P_EMAILADDRESS
                              WHERE CONTACTID = :CONTACTS.contactid
                              AND CONTACTTYPE = 'P';
      END;
      DECLARE
            duplicate_info EXCEPTION;
            PRAGMA EXCEPTION_INIT (duplicate_info, -00001);
      BEGIN
      INSERT INTO DBCONTACTPERSON
            (CONTACTID,      
             CONTACTTYPE,    
             TAXID,          
             PREFIX,        
             FIRSTNAME,      
             MIDDLENAME,    
             LASTNAME,      
             SUFFIX,
             BIRTHDATE,      
             MARITALSTATUS,  
             DENOMID,        
             CITIZEN,        
             EMAILADDRESS)
       VALUES
             (:CONTACTS.contactid,      
             'S',    
             :SECONDARY_CONTACT.S_TAXID,          
             :SECONDARY_CONTACT.S_PREFIX,        
             :SECONDARY_CONTACT.S_FIRSTNAME,      
             :SECONDARY_CONTACT.S_MIDDLENAME,    
             :SECONDARY_CONTACT.S_LASTNAME,      
             :SECONDARY_CONTACT.S_SUFFIX,
             :SECONDARY_CONTACT.S_BIRTHDATE,      
             :SECONDARY_CONTACT.S_MARITALSTATUS,  
             :SECONDARY_CONTACT.S_DENOMID,        
             :SECONDARY_CONTACT.S_CITIZEN,        
             :SECONDARY_CONTACT.S_EMAILADDRESS);
       EXCEPTION
               WHEN dup_val_on_index THEN
                     UPDATE DBCONTACTPERSON
                           SET TAXID                                          = :SECONDARY_CONTACT.S_TAXID,        
                                    PREFIX                        = :SECONDARY_CONTACT.S_PREFIX,    
                                    FIRSTNAME                     = :SECONDARY_CONTACT.S_FIRSTNAME,  
                                    MIDDLENAME                    = :SECONDARY_CONTACT.S_MIDDLENAME,  
                                    LASTNAME                   = :SECONDARY_CONTACT.S_LASTNAME,
                                    SUFFIX                     = :SECONDARY_CONTACT.S_SUFFIX,
                                    BIRTHDATE                  = :SECONDARY_CONTACT.S_BIRTHDATE,
                                    MARITALSTATUS              = :SECONDARY_CONTACT.S_MARITALSTATUS,
                                    DENOMID                    = :SECONDARY_CONTACT.S_DENOMID,
                                    CITIZEN                    = :SECONDARY_CONTACT.S_CITIZEN,
                                    EMAILADDRESS               = :SECONDARY_CONTACT.S_EMAILADDRESS
                        WHERE contactid = :CONTACTS.contactid
                        AND contacttype = 'S';
            END;
  DECLARE
            duplicate_info EXCEPTION;
            PRAGMA EXCEPTION_INIT (duplicate_info, -00001);
      BEGIN                   
  INSERT INTO DBCONTACTPERSON
         (CONTACTID,      
             CONTACTTYPE,    
             TAXID,          
             PREFIX,        
             FIRSTNAME,      
             MIDDLENAME,    
             LASTNAME,      
             SUFFIX,
             BIRTHDATE,      
             MARITALSTATUS,  
             DENOMID,        
             CITIZEN,        
             EMAILADDRESS)
       VALUES
             (:CONTACTS.contactid,      
             'T',    
             :TERTIARY_CONTACT.T_TAXID,          
             :TERTIARY_CONTACT.T_PREFIX,        
             :TERTIARY_CONTACT.T_FIRSTNAME,      
             :TERTIARY_CONTACT.T_MIDDLENAME,    
             :TERTIARY_CONTACT.T_LASTNAME,      
             :TERTIARY_CONTACT.T_SUFFIX,
             :TERTIARY_CONTACT.T_BIRTHDATE,      
             :TERTIARY_CONTACT.T_MARITALSTATUS,  
             :TERTIARY_CONTACT.T_DENOMID,        
             :TERTIARY_CONTACT.T_CITIZEN,        
             :TERTIARY_CONTACT.T_EMAILADDRESS);
       EXCEPTION
   WHEN dup_val_on_index THEN
                     UPDATE DBCONTACTPERSON
                           SET TAXID                                          = :TERTIARY_CONTACT.T_TAXID,        
                                    PREFIX                        = :TERTIARY_CONTACT.T_PREFIX,    
                                    FIRSTNAME                     = :TERTIARY_CONTACT.T_FIRSTNAME,  
                                    MIDDLENAME                    = :TERTIARY_CONTACT.T_MIDDLENAME,  
                                    LASTNAME                   = :TERTIARY_CONTACT.T_LASTNAME,
                                    SUFFIX                     = :TERTIARY_CONTACT.T_SUFFIX,
                                    BIRTHDATE                  = :TERTIARY_CONTACT.T_BIRTHDATE,
                                    MARITALSTATUS              = :TERTIARY_CONTACT.T_MARITALSTATUS,
                                    DENOMID                    = :TERTIARY_CONTACT.T_DENOMID,
                                    CITIZEN                    = :TERTIARY_CONTACT.T_CITIZEN,
                                    EMAILADDRESS               = :TERTIARY_CONTACT.T_EMAILADDRESS
                        WHERE contactid = :CONTACTS.contactid
                        AND contacttype = 'T';
       END;
       DECLARE
             Temp_ContactId            NUMBER;
             Temp_CategoryId            NUMBER;
             No_Data                                    EXCEPTION;
            PRAGMA EXCEPTION_INIT (no_data, -00001);
       BEGIN
             Temp_ContactId := :CONTACTS.CONTACTID;
             --MESSAGE('Temp_ContactId is ' || Temp_ContactId);
        SELECT Categoryid
          INTO   Temp_CategoryId
      from   dbconcats
      where  contactid = Temp_ContactId;
    EXCEPTION
               WHEN no_data_found THEN
               Temp_CategoryId := 1;      
    --MESSAGE('Temp_CategoryId is ' || Temp_CategoryId);
    IF Temp_CategoryId = 1
          THEN INSERT INTO dbconcats
                (categoryid,
                contactid)
                VALUES
                 (1,
                Temp_ContactID);
    END IF;
  END;       
               
END;
                  
0
 
LVL 15

Accepted Solution

by:
andrewst earned 500 total points
ID: 12309422
Could it be this returning more than one row?

      SELECT Categoryid
         INTO   Temp_CategoryId
      from   dbconcats
      where  contactid = Temp_ContactId;
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12309454
that's the only one I can see too....
0
 
LVL 9

Expert Comment

by:konektor
ID: 12309511
or check triggers of DBCONTACTPERSON, DBCONTACTS, ...
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12309637
if the error was in another trigger the error will show the trigger's name in the error listing...

SQL> create table test1(id number);

Table created.

SQL> create table test2(id number );

Table created.

SQL> create trigger test1trig after insert or update on test1 for each row
  2  begin
  3  insert into test2(id) values( :NEW.id );
  4  end;
  5  /

Trigger created.
SQL> create trigger test2trig after insert or update on test2 for each row
  2  declare
  3  tablename varchar2(1000);
  4  begin
  5  select table_name into tablename from user_tables;
  6  end;
  7  /

Trigger created.

SQL> insert into test2(id) values ( 3 );
insert into test2(id) values ( 3 )
            *
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCH.TEST2TRIG", line 4
ORA-04088: error during execution of trigger 'SCH.TEST2TRIG'


SQL> insert into test1(id) values( 2 );
insert into test1(id) values( 2 )
            *
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCH.TEST2TRIG", line 4
ORA-04088: error during execution of trigger 'SCH.TEST2TRIG'
ORA-06512: at "SCH.TEST1TRIG", line 2
ORA-04088: error during execution of trigger 'SCH.TEST1TRIG'

The first fail above is when the trigger itself is the problem.
The second error listing is when the error is in a trigger fired due the an insert in the trigger on the table updated...


So, to summarise, unless a seperate trigger is highlighted in the error, then the problem is in the trigger source listed above...
Actually, can you post the exact error?
0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 12311498
If you change this:
SELECT Categoryid INTO Temp_CategoryId from dbconcats where  contactid = Temp_ContactId;
to:
SELECT min(Categoryid) INTO Temp_CategoryId from dbconcats where  contactid = Temp_ContactId;
or:
SELECT max(Categoryid) INTO Temp_CategoryId from dbconcats where  contactid = Temp_ContactId;

Either of those should definitely avoid the "too many rows" error.  But what is correct, if there are actually multiple values that match?  That is a question we caoont answer, since we don't know your application.
0
 
LVL 7

Expert Comment

by:Bigfam5
ID: 12317748
You could also modify the SELECT

SELECT Categoryid     INTO   Temp_CategoryId
   from   dbconcats
   where  contactid = Temp_ContactId
      and rownum <=1;

0
 

Author Comment

by:uTab
ID: 12330576
Thanks for all of the help, I just needed a shove in the right direction.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question