1327-Undeclared variable:amount

1、错误描述

1327-Undeclared variable:amount_第1张图片


2、错误原因

BEGIN
	SELECT stuAge INTO amount;
  IF stuAge IS NOT NULL THEN
  SET stuAge = stuAge + 1;
  SELECT stuAge INTO amount1;
  ELSE
  SELECT 20 INTO amount2;
  END IF;
  SELECT stuAge INTO amount3;
END;

   amount实际是stuAge的别名,但是却写成了一个变量


3、解决办法

BEGIN
	SELECT stuAge AS amount;
  IF stuAge IS NOT NULL THEN
  SET stuAge = stuAge + 1;
  SELECT stuAge AS amount1;
  ELSE
  SELECT 20 INTO stuAge;
  END IF;
  SELECT stuAge AS amount3;
END


你可能感兴趣的:(MySQL)