문제

I want to use the loop index "i" in the result of my select statement in order to insert it into another table. Is is like:

set i=0;
while i<25 do

    insert into a (x,y,z)
    select a,b,i
    from table1;

    set i= i+1;
end while;

What is the way to do it?

도움이 되었습니까?

해결책

DOne :)

I have just created variable i as @i and it is all solved.

Like this:

set @i=0;
while @i<25 do

    insert into a (x,y,z)
    select a,b,@i
    from table1;

    set @i= @i+1;
end while;

thx anyway :)

다른 팁

Open the table separately asa cursor, put fields in to variables, then use those variables and i to insert data in to the table with a

insert into a (x,y,z) values (var1, var2, i).

What you have written would put multiple rows in to a table a with each value of i.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top