---When I run following code -
-
DECLARE
-
v_evct NUMBER(20);
-
v_evcd NUMBER(20);
-
v_class VARCHAR2(100);
-
cursor c1 is select * from input_info;
-
BEGIN
-
FOR r1 in c1
-
LOOP
-
SELECT sum(EV_COST),EV_ID,EV_ATTR INTO
-
v_evct,v_evcd,v_class
-
FROM cost_test GROUP BY EV_ID,EV_ATTR ;
-
END LOOP;
-
END ;
-
-
--I got this error
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 9
--cud u please tell me how to avoid this above error
11 2734
---When I run following code
DECLARE
v_evct NUMBER(20);
v_evcd NUMBER(20);
v_class VARCHAR2(100);
cursor c1 is select * from input_info;
BEGIN
FOR r1 in c1
LOOP
SELECT sum(EV_COST),EV_ID,EV_ATTR INTO
v_evct,v_evcd,v_class
FROM cost_test GROUP BY EV_ID,EV_ATTR ;
END LOOP;
END ;
--I got this error
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 9
--cud u please tell me how to avoid this above error
Please enclose your posted code in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use [code] tags in future.
I remember this is third time I am doing it for you and you have been already informed before to use CODE tags.
MODERATOR
---When I run following code -
-
DECLARE
-
v_evct NUMBER(20);
-
v_evcd NUMBER(20);
-
v_class VARCHAR2(100);
-
cursor c1 is select * from input_info;
-
BEGIN
-
FOR r1 in c1
-
LOOP
-
SELECT sum(EV_COST),EV_ID,EV_ATTR INTO
-
v_evct,v_evcd,v_class
-
FROM cost_test GROUP BY EV_ID,EV_ATTR ;
-
END LOOP;
-
END ;
-
-
--I got this error
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 9
--cud u please tell me how to avoid this above error
This error is becuase your SELECT query inside the loop is returning more than one row.
one more thing i notice is that you are using a FOR LOOP CURSOR, but not using any of the cursor values with in the loop then why you need to use a CURSOR here?
Thanks for ur reply -
DECLARE
-
v_evct NUMBER(20);
-
v_evcd NUMBER(20);
-
v_class VARCHAR2(100);
-
CURSOR c1 IS SELECT * FROM input_info;
-
BEGIN
-
FOR r1 IN c1
-
LOOP
-
SELECT SUM(EV_COST),EV_ID,EV_ATTR INTO
-
v_evct,v_evcd,v_class
-
FROM cost_test
-
Where accnum=r1.acc_num GROUP BY EV_ID,EV_ATTR ;
-
END LOOP;
-
END ;
-
still m getting that error any solution
I have tried that code for empno
still m getting that error ... cud u plz tell me how to avoid this error to get desired output ....
Thanks -
SQL> declare
-
2 v_empno number;
-
3 cursor c1 is select * from emp;
-
4 begin
-
5 for r1 in c1
-
6 loop
-
7 select empno into v_empno from emp where ename=r1.ename;
-
8 end loop;
-
9 end;
-
10 /
-
declare
*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 7
I have tried that code for empno
still m getting that error ... cud u plz tell me how to avoid this error to get desired output ....
Thanks -
SQL> declare
-
2 v_empno number;
-
3 cursor c1 is select * from emp;
-
4 begin
-
5 for r1 in c1
-
6 loop
-
7 select empno into v_empno from emp where ename=r1.ename;
-
8 end loop;
-
9 end;
-
10 /
-
declare
*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 7
Make use of primary key column in the where condition.
ename cannot be a primary key becuase many peoples can have same name.
Using empno in WHERE column will solve the error.
[HTML]
DECLARE
v_empno NUMBER;
CURSOR c1 IS SELECT * FROM emp;
BEGIN
FOR r1 IN c1
LOOP
SELECT empno INTO v_empno FROM emp WHERE ename=r1.ename;
END LOOP;
END;[/HTML]
when I execute this above code i am getting following error... ORA-01422: exact fetch returns more than requested number of rows
cud you please tell how to execute above code... any alternative code for above code..
Thanks
Threads merged for better management of the forum
MODERATOR
cud you please send me solution for above code ...m still not able to solve the above error and need your help for that ,,
[HTML]
DECLARE
v_empno NUMBER;
CURSOR c1 IS SELECT * FROM emp;
BEGIN
FOR r1 IN c1
LOOP
SELECT empno INTO v_empno FROM emp WHERE ename=r1.ename;
END LOOP;
END;[/HTML]
when I execute this above code i am getting following error... ORA-01422: exact fetch returns more than requested number of rows
cud you please tell how to execute above code... any alternative code for above code..
Thanks
If you look at the prevoius POSTS I have asked to use empno which is a primary key column in WHERE clause will resolve your issue.
Please try that and POST back in case of any further issues!!
Thanaks for ur answer.....But i dont want to use primary key for empno .. In my emp table empno has repeated values and if i used the primary key constraint it wont give me priveleges to do that ...
Could u please tell me whitout using primary key on empno (repeated values) how could I do this ..
Thanaks for ur answer.....But i dont want to use primary key for empno .. In my emp table empno has repeated values and if i used the primary key constraint it wont give me priveleges to do that ...
Could u please tell me whitout using primary key on empno (repeated values) how could I do this ..
Try below code: -
-
DECLARE
-
TYPE emp_no IS VARRAY(100) OF emp.empno%TYPE;
-
v_empno emp_no;
-
CURSOR c1 IS SELECT * FROM emp;
-
BEGIN
-
SELECT empno BULK COLLECT INTO v_empno FROM emp WHERE ename=r1.ename;
-
FOR I IN v_empno.FIRST..v_empno.LAST LOOP
-
DBMS_OUTPUT.PUT_LINE(v_empno);
-
END LOOP;
-
END;
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthew Houseman |
last post by:
All,
I've created a synonym that points to a package over a database link
like so:
CREATE SYNONYM API_MYLINK FOR USER.CSAPI_V2@INSTANCE.DOMAIN.COM
I've granted execute like so:
grant execute...
|
by: robert |
last post by:
Mr. Kyte's article doesn't use cursors, while Mr. Feuerstein's
book examples do. my recollection of conventional wisdom is
to avoid using cursors.
is this difference merely a question of style,...
|
by: php newbie |
last post by:
I am trying to write a cursor to update certain rows in a particular
order as follows: (I need the cursor version, not SQL, as the update
logic depends on the order of rows and some other...
|
by: Oliver Stratmann |
last post by:
Hello All!
We have a cursor in an application which fetches some data out of a DB2-DB.
Normally it all works kind of well.
We inserted a routine at certain places in order to do some...
|
by: Prashanth |
last post by:
I am getting this error from BEA DB2 Driver in weblogic console.
java.sql.SQLException: CURSOR C02 NOT IN A
PREPARED STATE
java.sql.SQLException: CURSOR C02 NOT IN A
PREPARED STATE
We keep...
|
by: dave |
last post by:
In my form Ive got a SaveData() routine that saves changes to a DB.
When I encounter an exception in the save operations, I am having
trouble chaning the cursor back to the default cursor, it just...
|
by: Søren Larsen |
last post by:
In a stored procedure (SP1) I am looping through a cursor with records
from Table1. Each record in the cursor is inserted into Table2.
Insert trigger on Table2 is inserting the record into Table3...
|
by: technocrat |
last post by:
Hi,
I am trying to declare and cursor and thn load from that cursor into
another table. Since I have almost 4 million records, I cant do it
without the cursor which reduces the time by almost...
|
by: invy |
last post by:
Hi,
I'm experiencing a problem while declaring scroll cursor. I'm
using Embeded SQL with C. my code is given below.
#ifdef SQLSRVR_RDBMS
EXEC SQL DECLARE CUR_DWNLD SCROLL CURSOR FOR SCURS;...
|
by: Florian Lindner |
last post by:
Hello,
I have a function that executes a SQL statement with MySQLdb:
def executeSQL(sql, *args):
print sql % args
cursor = conn.cursor()
cursor.execute(sql, args)
cursor.close()
it's...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |