The stored procedure sqlserver to Mysql, is mainly the cursor! Heroes to help ah

CREATE PROCEDURE [dbo].[DeviceClassified] AS
Declare @frTe int
Declare @toTe int
Declare @baseTe int
Declare @plusTe int
set @baseTe=0
set @plusTe=0

--Lead table
Declare cursor_lead Cursor For
SELECT F1014_FTID,F1014_TTID FROM TB1014_LEAD
For Update

OPEN cursor_lead
While(0=0)
BEGIN
Fetch Next From cursor_lead Into @frTe,@toTe
if(@@Fetch_Status<>0) Break
set @baseTe = @plusTe+1
set @plusTe = @baseTe+1
Update TB1014_LEAD Set F1014_FTID=@baseTe,F1014_TTID=@plusTe
Where Current of cursor_lead
END

Close cursor_lead
Deallocate cursor_lead

Started by Eric at November 23, 2016 - 8:23 PM

Deallocate cursor:
CREATE PROCEDURE curdemo(IN V_GROUP INT)
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE a INT;
DECLARE b CHAR(16);

DECLARE cur1 CURSOR FOR SELECT id,name FROM student where classid=V_GROUP;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

OPEN cur1;

REPEAT
FETCH cur1 INTO a, b;
select a,b;
UNTIL done END REPEAT;

CLOSE cur1;
END;

Posted by Tim at November 28, 2016 - 8:58 PM

The format I know, is the SELECT F1014_FTID,F1014_TTID FROM TB1014_LEAD
For Update

OPEN cursor_lead
While(0=0)
BEGIN
Fetch Next From cursor_lead Into @frTe,@toTe
if(@@Fetch_Status<>0) Break
set @baseTe = @plusTe+1
set @plusTe = @baseTe+1
Update TB1014_LEAD Set F1014_FTID=@baseTe,F1014_TTID=@plusTe
Where Current of cursor_lead
END
This how to, select for update............. You can give me, turn under it, probably right to compile my to adjust, give you score

Posted by Eric at December 13, 2016 - 9:13 PM

Reference to the 1 floor of the code
DECLARE done INT DEFAULT 0;
DECLARE a INT;
DECLARE b CHAR(16);

Declare cursor_lead Cursor For
SELECT F1014_FTID,F1014_TTID FROM TB1014_LEAD;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

OPEN cursor_lead;

REPEAT
FETCH cursor_lead INTO @frTe,@toTe;
set @baseTe = @plusTe+1;
set @plusTe = @baseTe+1;
Update TB1014_LEAD Set F1014_FTID=@baseTe,F1014_TTID=@plusTe;
UNTIL done END REPEAT;

CLOSE cursor_lead;

Posted by Tim at December 19, 2016 - 9:17 PM