p°φkaz_UPDATE_CURRENT_OF
::= UPDATE [ tabulka ] SET
p°i°azenφ
{,
p°i°azenφ
}à WHERE CURRENT OF jmΘno_kurzoru;
P°φkaz UPDATE CURRENT OF provede zm∞ny zadanΘ p°i°azenφmi na °ßdce, na nφ₧ je nastaven kurzor zadan² jmΘnem_kurzoru. JmΘno_kurzoru musφ b²t bu∩ deklarovßno v deklaraci_kurzoru nebo musφ oznaΦovat dotaz pat°φcφ do aplikace a ulo₧en² v databßzi. Sloupce uvedenΘ na levΘ stran∞ vÜech p°i°azenφ musφ b²t editovatelnΘ.
Je-li v p°φkazu uvedena tabulka, musφ to b²t (jedinß) tabulka zp°φstupn∞nß zadan²m kurzorem.
Pokud zadan² kurzor nenφ otev°en ), nastane chybov² sqlstate 34000, pokud nenφ nastaven na n∞kter² °ßdek (nap°. je p°ed prvnφm nebo za poslednφm °ßdkem), nastane chybov² sqlstate 24000. Je-li p°φkaz proveden v transakci READ ONLY, nastane chybov² sqlstate 25006.
P°φklad pou₧itφ:
Zm∞≥te cenu u polo₧ek cenφku takto: polo₧ky cenφku zaΦφnajφcφ na X sni₧te o 10%, zaΦφnajφcφ na A zvyÜte o 100%, ostatnφ sma₧te. Je to obdoba p°φkladu pou₧itΘho pro demonstraci p°φkazu FOR:
PROCEDURE ZmenaCeniku();
BEGIN
DECLARE err_notfound BIT DEFAULT FALSE;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' BEGIN SET err_notfound=TRUE; END;
DECLARE curcen SENSITIVE CURSOR FOR
SELECT cislo_pol, cena
FROM Cenik
FOR UPDATE;
DECLARE Polozka CHAR(20);
DECLARE Cena NUMERIC(14,2);
OPEN curcen;
LabelLoop: LOOP
FETCH NEXT FROM curcen INTO Polozka, Cena;
IF err_notfound IS TRUE THEN LEAVE LabelLoop; END IF;
IF SUBSTRING(Polozka FROM 1 FOR 1) = "X" THEN
UPDATE SET Cena = Cena*0.9 WHERE CURRENT OF curcen;
ELSEIF SUBSTRING(Polozka FROM 1 FOR 1) = "A" THEN
UPDATE SET Cena = Cena*2 WHERE CURRENT OF curcen;
ELSE
DELETE WHERE CURRENT OF curcen;
END IF;
END LOOP LabelLoop;
CLOSE curcen;
END;