Hallo ich veruche momentan einen Cursor aus dem Internet umzusetzen
de.education-wiki.com
Ein beispiel bei dem ein Gehalt aktualisiert wird, ich möchte das als stored procedure erstellen
SELECT * FROM uebung.employees;
Insert Into Employees Values ( NULL , 'John', 35000, NULL),
( NULL , 'Jil', 50000, NULL ),
( NULL, 'Jacob', 40000, NULL),
( NULL, 'JMatt', 55000, NULL),
(NULL , 'Carla', 60000,NULL );
DELIMITER //
CREATE PROCEDURE p1()
DECLARE sal float;
DECLARE newsal float;
DECLARE Emp_Cur CURSOR FOR SELECT Salary, Updated_Salary FROM Employees;
OPEN Emp_Cur
FETCH NEXT FROM Emp_Cur INTO sal, newsal
WHILE @@FETCH_STATUS = 0
BEGIN
SET @newsal = @sal*1.25
UPDATE Employees SET Updated_Salary = newsal WHERE CURRENT OF Emp_Cur
FETCH NEXT FROM Emp_Cur INTO @sal, newsal
END
CLOSE Emp_Cur
DEALLOCATE Emp_Cur
DELIMITER ;
Kann mir jemand weiter helfen ? warum funktioniert das nicht.
bin beim Thema Cursos etwas ahnungslos
Cursor in SQL - Typen und Lebenszyklus Terminologie mit Beispiel & Syntax | Web-Entwicklungstools 2025
Anleitung zu Cursorn in SQL. Hier diskutieren wir die verschiedenen Typen, den Lebenszyklus und die Terminologie von Cursorn in SQL mit Beispielen und Syntax.
Ein beispiel bei dem ein Gehalt aktualisiert wird, ich möchte das als stored procedure erstellen
SELECT * FROM uebung.employees;
Insert Into Employees Values ( NULL , 'John', 35000, NULL),
( NULL , 'Jil', 50000, NULL ),
( NULL, 'Jacob', 40000, NULL),
( NULL, 'JMatt', 55000, NULL),
(NULL , 'Carla', 60000,NULL );
DELIMITER //
CREATE PROCEDURE p1()
DECLARE sal float;
DECLARE newsal float;
DECLARE Emp_Cur CURSOR FOR SELECT Salary, Updated_Salary FROM Employees;
OPEN Emp_Cur
FETCH NEXT FROM Emp_Cur INTO sal, newsal
WHILE @@FETCH_STATUS = 0
BEGIN
SET @newsal = @sal*1.25
UPDATE Employees SET Updated_Salary = newsal WHERE CURRENT OF Emp_Cur
FETCH NEXT FROM Emp_Cur INTO @sal, newsal
END
CLOSE Emp_Cur
DEALLOCATE Emp_Cur
DELIMITER ;
Kann mir jemand weiter helfen ? warum funktioniert das nicht.
bin beim Thema Cursos etwas ahnungslos
