DROP PROCEDURE IF the EXISTS CURSOR_test;
Delimiter//
# to create a stored procedure called xw
CREATE PROCEDURE xw ()
The BEGIN
# statement three variables
DECLARE vend_id VARCHAR (255);
DECLARE prod_id VARCHAR (255);
DECLARE prod_price VARCHAR (255);
# traversal data end mark
DECLARE the done INT the DEFAULT FALSE;
# define a cursor called mycursor
DECLARE mycursor CURSOR FOR the SELECT * FROM abcd.
# will end symbol is bound to the cursor
DECLARE the CONTINUE HANDLER FOR the NOT FOUND SET done=TRUE;
# to open the cursor
The OPEN mycursor;
# start cycle
Read_loop: LOOP
The FETCH mycursor INTO vend_id prod_id, prod_price;
IF done THEN
LEAVE read_loop;
END the IF;
INSERT INTO abcd VALUES (vend_id, prod_id, prod_price);
END LOOP read_loop;
# close the cursor
The CLOSE mycursor;
END;//
Delimiter.
CALL xw ();
SELECT * FROM abcd.
Beginners, why each time you run cycles are different
CodePudding user response:
INSERT INTO abcd VALUES (vend_id, prod_id, prod_price);So it's different for