Die folgende Prozedur benutzt einen aktualisierbaren Cursor für die SELECT-Anweisung. Damit wird gezeigt, wie eine UPDATE-Anweisung für eine Zeile mit der gespeicherten Prozedur durchgeführt wird.
CREATE PROCEDURE UpdateSalary( IN employeeIdent INT, IN salaryIncrease NUMERIC(10,3) ) BEGIN -- Procedure to increase (or decrease) an employee's salary DECLARE err_notfound EXCEPTION FOR SQLSTATE '02000'; DECLARE oldSalary NUMERIC(20,3); DECLARE employeeCursor CURSOR FOR SELECT Salary from Employees WHERE EmployeeID = employeeIdent FOR UPDATE; OPEN employeeCursor; FETCH employeeCursor INTO oldSalary FOR UPDATE; IF SQLSTATE = err_notfound THEN MESSAGE 'No such employee' TO CLIENT; ELSE UPDATE Employees SET Salary = oldSalary + salaryIncrease WHERE CURRENT OF employeeCursor; END IF; CLOSE employeeCursor; END; |
Die folgende Anweisung ruft die obige gespeicherte Prozedur auf:
CALL UpdateSalary( 105, 220.00 ); |
Kommentieren Sie diese Seite in DocCommentXchange. Senden Sie uns Feedback über diese Seite via E-Mail. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |