Home » Developer & Programmer » Forms » Ora-06511 - Cursor already open - Trigger raised unhandled exception. (Oracle 6i forms, windows Xp (Database 10g))
icon4.gif  Ora-06511 - Cursor already open - Trigger raised unhandled exception. [message #550883] Fri, 13 April 2012 04:10 Go to next message
stalin4d
Messages: 226
Registered: May 2010
Location: Chennai, Tamil Nadu, Indi...
Senior Member
Dear,

I getting a error
Ora-06511
when-new-item-instance trigger raised unhandled exception.

below is the coding for the trigger when-new-item-instance :
where the cursor is open? how to close it?


if :blk_master.action_status = 'A' then
	declare
		doc_slno number;
		doc_1_dig varchar2(1);  -- I digit of DOCUMENT No.
		f_doc_no varchar2(6);  
	begin
	  begin
		  Select last_no+1 into doc_slno
		  from control_nos
		  where process_id='ISS' and control_id1=:keyblock.store_no and control_id2= :keyblock.tran_type;
	  exception 
	  	when others then
	  		msg_error ('Error selecting from control_nos @ keyblock.doc_no.when-new-item-instance');
	  end;
	  
	  loop
			doc_1_dig := get_doc_1_digit (:keyblock.store_no);	  	
			f_doc_no := doc_1_dig||to_char(doc_slno,'FM00000');
	  	declare
	  		f_doc_date date;
	  		cursor c1 is 
	  			select document_date
	  			from issue_tran_head
	  			where document_no = f_doc_no;
	  	begin
	  		open c1;
	  		fetch c1 into f_doc_date;
	  		if c1%notfound then
	  			close c1;
	  			exit;
	  		end if;
	  		if financial_year_beg(f_doc_date) <> financial_year_beg(sysdate) then
	  			close c1;
	  			exit;
	  		end if;
	  	end;
	  	doc_slno := doc_slno + 1;
	  end loop;
	  :keyblock.doc_no := f_doc_no;
end;
set_item_property('keyblock.doc_no',update_allowed,property_false);
next_item;
else
	set_item_property('keyblock.doc_no',update_allowed,property_true);
end if;	  						
		
Re: Ora-06511 - Cursor already open - Trigger raised unhandled exception. [message #550884 is a reply to message #550883] Fri, 13 April 2012 04:19 Go to previous messageGo to next message
Littlefoot
Messages: 21813
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Switch to cursor FOR loop, which handles such stuff for you.

Here, you opened a cursor, close it if c1%notfound or if financial_year_beg condition is met. But, you don't close it if it is not met so it stays opened and the next LOOP round tries to open it - but guess what - it is already open!

By the way, the way you use cursor C1 is unnecessary. You seem to be fetching a single value into F_DOC_DATE. To do that, you don't need a cursor - an ordinary SELECT statement is perfectly capable of doing it.

I'd say that this code should be rewritten in order to make it smaller and, hopefully, more efficient.
Re: Ora-06511 - Cursor already open - Trigger raised unhandled exception. [message #550958 is a reply to message #550884] Fri, 13 April 2012 16:42 Go to previous messageGo to next message
owais_baba
Messages: 289
Registered: March 2008
Location: MUSCAT
Senior Member
let me give some example regarding open and close cursor in a proper way

declare
  cursor c1 is select * from emp;
  a emp%rowtype;

begin 
  open c1;
     for i in 1..50 loop
           fetch c1 into a
     exit when c1%notfound;

      insert into testing values(a.ename,a.sal);
  end loop;
      close c1;
  end;


regards
baba








Re: Ora-06511 - Cursor already open - Trigger raised unhandled exception. [message #550960 is a reply to message #550958] Fri, 13 April 2012 17:18 Go to previous message
cookiemonster
Messages: 13925
Registered: September 2008
Location: Rainy Manchester
Senior Member
You you think that's a proper way? Using a non-cursor for loop to iterate over a cursor?
You want to loop over a cursor, use a cursor for loop:
declare
  cursor c1 is select * from emp;

begin 
  for rec in c1 loop
     
    insert into testing values(rec.ename,rec.sal);

  end loop;

end;
Previous Topic: Bean not found when form is loaded
Next Topic: frm-40735
Goto Forum:
  


Current Time: Fri Jul 05 21:43:36 CDT 2024