drop procedure if exists test_cursor
/

create procedure test_cursor()
	
	
begin

--
-- variables
--
declare hasMoreRows bool default true;
declare _field1 varchar(20);
declare _field2 varchar(20);


--
-- the cursor
--
declare cur cursor for
		
	select
	    cl.LIBRARY_NAME,
	    cl.LIBRARY_DESCRIPTION
	from
	    CAT_LIBRARIES as cl
	;
	
declare continue handler for SQLSTATE '02000'
    set hasMoreRows = false;
    

--
-- create table test
--
drop table if exists test_cursor;

create table `test_cursor` ( 
	`field1`	varchar(20) NULL,
	`field2`	varchar(20) NULL 
);
	
--
-- open the cursor
--	    
open cur;

fetch cur into 
	_field1,
	_field2;

while hasMoreRows do

--
-- ####### WALK:INI ########
--
	
	
	insert into
	    test_cursor
	set
		field1 = _field1,
		field2 = _field2
	;
	
	
--
-- ####### WALK:END ########
--
	      
	fetch cur into 
		_field1,
		_field2;
			
end while;

close cur;


end;
/



