The GOTO statement is used to branch to a user-defined label within an SQL procedure.
This statement can only be embedded in an SQL procedure. It is not an executable statement and cannot be dynamically prepared.
None required.
In the following compound statement, the parameters rating and v_empno are passed into the procedure, which then returns the output parameter return_parm as a date duration. If the employee's time in service with the company is less than 6 months, the GOTO statement transfers control to the end of the procedure, and new_salary is left unchanged.
CREATE PROCEDURE adjust_salary
(IN v_empno CHAR(6),
IN rating INTEGER,
OUT return_parm DECIMAL (8,2))
MODIFIES SQL DATA
LANGUAGE SQL
BEGIN
DECLARE new_salary DECIMAL (9,2);
DECLARE service DECIMAL (8,2);
SELECT SALARY, CURRENT_DATE - HIREDATE
INTO new_salary, service
FROM EMPLOYEE
WHERE EMPNO = v_empno;
IF service < 600
THEN GOTO EXIT;
END IF;
IF rating = 1
THEN SET new_salary = new_salary + (new_salary * .10);
ELSEIF rating = 2
THEN SET new_salary = new_salary + (new_salary * .05);
END IF;
UPDATE EMPLOYEE
SET SALARY = new_salary
WHERE EMPNO = v_empno;
EXIT: SET return_parm = service;
END