Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I have written a stored procedure which uses cursor to fetch a column and insert into another table.


Below is my code,

SQL
delimiter //
CREATE PROCEDURE curdemo()
BEGIN
  DECLARE done INT DEFAULT 0;  
  DECLARE a INT;
  DECLARE cur1 CURSOR FOR SELECT intCid FROM tblcountries; 
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  OPEN cur1; 
  while not done do
          FETCH cur1 INTO a; 
		INSERT INTO t1(n1) VALUES (a);   
  END while;
  CLOSE cur1;
  
END
//


My problem is last record alone getting inserted twice. How to solve this?
Posted
Updated 6-Feb-13 22:57pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900