if 需要 end if;
CREATE PROCEDURE UPDATE_SAL (IN empNum CHAR(6), OUT rating SMALLINT)LANGUAGE SQLBEGINIF rating = 1 THENUPDATE employee SET salary = salary * 1.10, bonus = 1000 WHERE empno = empNum;ELSEIF rating = 2 THENUPDATE employee SET salary = salary * 1.05, bonus = 500 WHERE empno = empNum;ELSEUPDATE employee SET salary = salary * 1.03, bonus = 0 WHERE empno = empNum;END IF;END
调用: call UPDATE_SAL('emp001',?)
复杂的(主要关注BEGIN和END)
BEGINBEGINBEGINIF NOT EXISTS(SELECT 1 FROM STUDENT FETCH FIRST 1 ROWS ONLY) THENCALL TEST('');ELSEBEGINIF EXISTS (SELECT 1 FROM STUDENT FETCH FIRST 1 ROWS ONLY) THEN BEGINIF DEMO('AA')=1 THEN CALL TEST('');END IF;END;ELSEBEGINEND;END IF;END;END IF;END;END;
END
SQL 过程中的 IF 语句 - IBM 文档