cursors [message #283683] |
Tue, 27 November 2007 23:41 |
varu123
Messages: 754 Registered: October 2007
|
Senior Member |
|
|
How to use two cursors in a single declare statement?
I ahve to generate two text files in a form.
I am doing like this:
declare
cursor1;
cursor2;
begin
open cursor1;
loop
fetch ....
text_io.put_file('...');
exit when cursor1%notfound;
end loop;
text_io.fclose(file1);
begin
open cursor2;
loop
fetch ...
text_io.putfile(..);
exit when cursor2%notfound;
end loop;
text_io.fclose(file2);
forms_ddl('commit');
end;
end;
When i run the form the text file corresponding to cursor1 gets generated with data but the file for cursor2 is empty with forms run time exception ora-06502.
I have run the cursors individually and they run fine and generate text files with data.
Its only when i try to combine them.
It seems i havent used the cursors appropriately.
Any advices?
[EDITED by LF: set the indentation to improve readability. Next time do it yourself, please.]
[Updated on: Wed, 28 November 2007 01:05] by Moderator Report message to a moderator
|
|
|
Re: cursors [message #283687 is a reply to message #283683] |
Tue, 27 November 2007 23:56 |
dhananjay
Messages: 635 Registered: March 2002 Location: Mumbai
|
Senior Member |
|
|
this is what the error has to say:
ORA-06502: PL/SQL: numeric or value error string
Cause: An arithmetic, numeric, string, conversion, or constraint error occurred.
For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL,
or if an attempt is made to assign an integer larger than 99 to a variable declared NUMBER(2).
Action: Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.
regards,
[Updated on: Tue, 27 November 2007 23:58] Report message to a moderator
|
|
|
Re: cursors [message #283691 is a reply to message #283683] |
Wed, 28 November 2007 00:04 |
varu123
Messages: 754 Registered: October 2007
|
Senior Member |
|
|
I know buddy what this error mean?
But when i run these cursors individually,they run fine.It is only when i combine the cursors this error occurs and only for cursor2.
Cursor1 runs fine and generate a text file.
That means iam somewhere wrong with the use of multiple cursors but don't no where.
The sample i provided is the outline of how i am using the cursors.
|
|
|
|
Re: cursors [message #283771 is a reply to message #283683] |
Wed, 28 November 2007 02:16 |
varu123
Messages: 754 Registered: October 2007
|
Senior Member |
|
|
Thanks for your concern Littlefoot.
I Tried with what you suggested but the same error.
only the first cursor works.
I am using the same cursor variables in both the fetch statements.
for ex.
declare
tcode varchar2(9);
cursor1;
cursor2;
begin
open cursor1;
loop
fetch cursor1 into tcode;
exit when cursor1%notfound;
text_io.put_file(tcode);
end loop;
fclose(file1);
begin
open cursor2;
loop
fetch cursor2 into tcode;
exit when cursor2%notfound;
text_io.put_line(tcode);
end loop;
fclose(file2);
close cursor1;
end;
close cursor2;
end;
|
|
|
|
Re: cursors [message #283785 is a reply to message #283683] |
Wed, 28 November 2007 02:47 |
varu123
Messages: 754 Registered: October 2007
|
Senior Member |
|
|
Thanks Taj,posted it before reading Michel's reply
Now the makeup is done
So where am i wrong?
|
|
|
Re: cursors [message #287896 is a reply to message #283785] |
Fri, 14 December 2007 00:26 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
Have you solved your problem?
Without seeing all the code for the separate cursor #2 and the combined cursor #2 I would say that you have a typo in the latter which is causing no records to be retrieved.
You are also not showing explicit 'open file' statements. Are both output files in the same directory? If different directories are they both defined at the database level? Have you inadvertently put a 'space' in one of the file names?
David
|
|
|