Solved

FRM-40735:KEY-COMMIT trigger raised unhandled exception ORA-01422

Posted on 2016-11-14
7
110 Views
Last Modified: 2016-11-15
hi am having this error when saving this is my block
 BEGIN
        select emp_adress,
               emp_name,
               emp_surname,
        into   ws_address,
               ws_name,
               ws_surname
        from   employee
        where  empid    = :p_empid      and
               (empacc  = :p_accnr or
                idno    = :p_idno);
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
             message('Employee account for this acc No: '||:p_accnr||
                      ' or '||'ID No: '||:p_idno);	
             raise form_trigger_failure;
    END;

Open in new window

0
Comment
Question by:chalie001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 22

Expert Comment

by:Helena Marková
ID: 41887459
This is the error:
ORA-01422: exact fetch returns more than requested number of rows
Cause: The number specified in exact fetch is less than the rows returned.

Action: Rewrite the query or change number of rows requested

You can change your code:
BEGIN
        select emp_adress,
               emp_name,
               emp_surname,
        into   ws_address,
               ws_name,
               ws_surname
        from   employee
        where  empid    = :p_empid      and
               (empacc  = :p_accnr or
                idno    = :p_idno);
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
             message('Employee account for this acc No: '||:p_accnr||
                      ' or '||'ID No: '||:p_idno);      
             raise form_trigger_failure;
       WHEN TOO_MANY_ROWS THEN
             message('Too many rows for this acc No: '||:p_accnr||
                      ' or '||'ID No: '||:p_idno);      
             raise form_trigger_failure;

    END;

Here are predefined exceptions:
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/errors.htm#LNPLS00703
0
 

Author Comment

by:chalie001
ID: 41887582
How can I re-write the query
0
 

Author Comment

by:chalie001
ID: 41887650
how can i do this
- collect all the records returned by SELECT in collection (bulk collect)
- open a cursor for select and loop through it
- if you need only one record, add rownum = 1

if data is like this
CREATE TABLE employee 
   (emp_adress VARCHAR2(10 BYTE), 
	emp_name VARCHAR2(13 BYTE), 
	emp_surname VARCHAR2(8 BYTE), 
	empid VARCHAR2(5 BYTE), 
	empacc VARCHAR2(35 BYTE), 
	idno VARCHAR2(2 BYTE)
   ) 
Insert into employee (empacc,idno,empid,emp_surname,emp_name,emp_adress) values ('90415373',null,'PTE','MS','ADAMS',null);
Insert into employee (empacc,idno,empid,emp_surname,emp_name,emp_adress) values ('90415373',null,'PTE','MS','ADAMS',null);

Open in new window

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 22

Expert Comment

by:Helena Marková
ID: 41887654
select emp_adress,
                emp_name,
                emp_surname,
         into   ws_address,
                ws_name,
                ws_surname
         from   employee
         where  empid    = :p_empid      and
                (empacc  = :p_accnr or
                 idno    = :p_idno) AND rownum<2;
0
 

Author Comment

by:chalie001
ID: 41887672
this is the constraint
ALTER TABLE employee ADD PRIMARY KEY (empacc, idno) DISABLE;
 ALTER TABLE employee MODIFY (empid NOT NULL ENABLE);
0
 
LVL 22

Accepted Solution

by:
Helena Marková earned 500 total points
ID: 41887683
What is the problem now ? Doesn't AND rownum<2; in my last post work, does it ?
0
 

Author Closing Comment

by:chalie001
ID: 41887928
Rownum=1
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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