472,776 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,776 software developers and data experts.

Cursor Error

75
---When I run following code

Expand|Select|Wrap|Line Numbers
  1.  
  2. DECLARE
  3.       v_evct   NUMBER(20);
  4.       v_evcd    NUMBER(20);
  5.       v_class      VARCHAR2(100);
  6.        cursor c1 is select * from input_info;
  7. BEGIN
  8.       FOR r1 in c1
  9.       LOOP
  10.           SELECT sum(EV_COST),EV_ID,EV_ATTR   INTO
  11.           v_evct,v_evcd,v_class                   
  12.             FROM cost_test GROUP BY EV_ID,EV_ATTR  ;
  13.      END LOOP;
  14. END ;
  15.  
  16.  
--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
Nov 16 '07 #1
11 2734
amitpatel66
2,367 Expert 2GB
---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
Nov 16 '07 #2
amitpatel66
2,367 Expert 2GB
---When I run following code

Expand|Select|Wrap|Line Numbers
  1.  
  2. DECLARE
  3.       v_evct   NUMBER(20);
  4.       v_evcd    NUMBER(20);
  5.       v_class      VARCHAR2(100);
  6.        cursor c1 is select * from input_info;
  7. BEGIN
  8.       FOR r1 in c1
  9.       LOOP
  10.           SELECT sum(EV_COST),EV_ID,EV_ATTR   INTO
  11.           v_evct,v_evcd,v_class                   
  12.             FROM cost_test GROUP BY EV_ID,EV_ATTR  ;
  13.      END LOOP;
  14. END ;
  15.  
  16.  
--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?
Nov 16 '07 #3
orajit
75
Thanks for ur reply

Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2.       v_evct   NUMBER(20);
  3.       v_evcd    NUMBER(20);
  4.       v_class      VARCHAR2(100);
  5.        CURSOR c1 IS SELECT * FROM input_info;
  6. BEGIN
  7.       FOR r1 IN c1
  8.       LOOP
  9.           SELECT SUM(EV_COST),EV_ID,EV_ATTR   INTO
  10.           v_evct,v_evcd,v_class                   
  11.             FROM cost_test
  12.              Where accnum=r1.acc_num  GROUP BY EV_ID,EV_ATTR  ;
  13.      END LOOP;
  14. END ;
  15.  
still m getting that error any solution
Nov 16 '07 #4
orajit
75
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
Expand|Select|Wrap|Line Numbers
  1. SQL> declare 
  2.   2    v_empno number;
  3.   3    cursor c1 is select * from emp;
  4.   4  begin 
  5.   5    for r1 in c1
  6.   6     loop 
  7.   7      select empno into v_empno from emp where ename=r1.ename;
  8.   8  end loop;
  9.   9  end;
  10.  10  /
  11.  
declare
*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at line 7
Nov 16 '07 #5
amitpatel66
2,367 Expert 2GB
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
Expand|Select|Wrap|Line Numbers
  1. SQL> declare 
  2.   2    v_empno number;
  3.   3    cursor c1 is select * from emp;
  4.   4  begin 
  5.   5    for r1 in c1
  6.   6     loop 
  7.   7      select empno into v_empno from emp where ename=r1.ename;
  8.   8  end loop;
  9.   9  end;
  10.  10  /
  11.  
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.
Nov 16 '07 #6
orajit
75
[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
Nov 19 '07 #7
amitpatel66
2,367 Expert 2GB
Threads merged for better management of the forum

MODERATOR
Nov 19 '07 #8
orajit
75
cud you please send me solution for above code ...m still not able to solve the above error and need your help for that ,,
Nov 19 '07 #9
amitpatel66
2,367 Expert 2GB
[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!!
Nov 19 '07 #10
orajit
75
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 ..
Nov 19 '07 #11
amitpatel66
2,367 Expert 2GB
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. DECLARE 
  3.     TYPE emp_no IS VARRAY(100) OF emp.empno%TYPE;
  4.     v_empno emp_no;
  5.     CURSOR c1 IS SELECT * FROM emp;
  6.   BEGIN 
  7.      SELECT empno BULK COLLECT INTO v_empno FROM emp WHERE ename=r1.ename;
  8. FOR I IN v_empno.FIRST..v_empno.LAST LOOP
  9. DBMS_OUTPUT.PUT_LINE(v_empno);
  10. END LOOP;
  11.   END;
  12.  
  13.  
Nov 19 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
3
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,...
2
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...
4
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...
0
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...
2
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...
1
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...
10
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...
4
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;...
2
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...
3
isladogs
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...
0
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...
0
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 ...
14
DJRhino1175
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...
0
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...
5
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...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.