[MySQL] zapętlona procedurka - pomóżcie

0

Czesc
Napisałam procedurkę, której zadaniem jest update pola NN w tabeli testcasesTMP tak aby zaczynało sie od max(id)+1 pola ID z innej tabeli (testcases), a w następnych rekordach tabeli testcasesTMPzwiększało się o 1. N
Problem polega na tym, że zapętliła mi sie ta procedurka. Tylko nie wiem, w którym miejscu. Będę wdzięczna za wskazówki.

DELIMITER //
create procedure test ()
BEGIN
declare nrIDcase int;
declare nastepny int;
select max(ID) + 1 from testcases into nrIDcase;
select ID from testcasesTMP where NN is null limit 1 into nastepny;
while
nastepny > 0 do
update testcasesTMP set NN = nrIDcase where ID=nastepny;
set nrIDcase=nrIDcase+1;
select ID from testcasesTMP where NN is null limit 1 into nastepny;
end while;
END//
DELIMITER ;

Pozdrawiam
Zuzia

0

nie chce mi się sprawdzać ale sprawdz po każdym select into zmienna czy zmienna jest równa null. Jak tak to przypisz jej 0. Czyli coś na kształt

DELIMITER //
create procedure test ()
BEGIN
declare nrIDcase int;
declare nastepny int;
select max(ID) + 1 from testcases into nrIDcase;
if (nrIDcase is null) then
  nrIDcase = 0;
select ID from testcasesTMP where NN is null limit 1 into nastepny;
while nastepny > 0 do
  update testcasesTMP set NN = nrIDcase where ID=nastepny;
  set nrIDcase=nrIDcase+1;
  select ID from testcasesTMP where NN is null limit 1 into nastepny;
  if (nastepny is null) then
    nastepny = 0;
end while;
END//
DELIMITER ;

nie wiem jak to w mysqlu jest ale może zamiast zmienna is null trzeba sprawdzać zmienna = null

1 użytkowników online, w tym zalogowanych: 0, gości: 1