如何在 MySQL 的触发器中声明变量?因为我在执行几行代码时遇到错误
我想在 MySql 中执行以下代码,但出现错误
I want to execute the following code in MySql but I am getting the error
CREATE TRIGGER CINEMAHALLNO_GENERATE_TRIGGER
BEFORE INSERT ON CINEMA_HALLS
FOR EACH ROW
BEGIN
DECLARE cnt DOUBLE;
DECLARE next1 DOUBLE;
SELECT COUNT(HALLNO) INTO cnt from CINEMA_HALLS;
IF cnt > 0 AND cnt < 20 THEN
SELECT MAX(HALLNO) INTO NEXT1 FROM CINEMA_HALLS;
set next1=next1+1;
SET :new.HALLNO=next;
ELSEIF cnt = 0 THEN
SET :new.HALLNO=1;
end if;
end;
输出错误:SQL查询:
Output Error: SQL query:
创建触发器 CINEMAHALLNO_GENERATE_TRIGGER在 CINEMA_HALLS 上插入之前每一行开始声明 cnt DOUBLEMySQL 说:文档
CREATE TRIGGER CINEMAHALLNO_GENERATE_TRIGGER BEFORE INSERT ON CINEMA_HALLS FOR EACH ROW BEGIN DECLARE cnt DOUBLE MySQL said: Documentation
推荐答案
Declare 必须放在 Begin 之后.请查看以下链接
Declare must be placed after the Begin. Please check the following link
相关文章