声明变量和错误时出错if语句

时间:2016-09-09 16:19:12

标签: db2

我正在尝试编写一个使用if语句和变量的存储过程但是我不断收到SQL0104N错误。它似乎很难声明变量。我也尝试用'@'替换'v'前缀来表示局部变量,但它似乎没有帮助。错误表示未检错的令牌'DECLARE vCUBE DOUBLE'

任何见解都会非常有用。代码如下:

CREATE PROCEDURE DIMENSION_CALC(
  IN iORID INTEGER,
  IN iPIECES DOUBLE,
  IN iLENGTH_1 DOUBLE,
  IN iLENGTH_UNITS DOUBLE,
  IN iWIDTH DOUBLE,
  IN iWIDTH_UNITS DOUBLE,
  IN iHEIGHT DOUBLE,
  IN iHEIGHT_UNITS DOUBLE,
  IN iCUBE DOUBLE,
  IN iCUBE_UNITS DOUBLE
  )
LANGUAGE SQL
BEGIN
  DECLARE vCUBE DOUBLE;
  DECLARE vLINEAR DOUBLE;
  SET vCUBE = iPIECES * GET_CUBE(iCUBE, iCUBE_UNITS, iHEIGHT, iHEIGHT_UNITS, iWIDTH, iWIDTH_UNITS, iLENGTH_1, iLENGTH_UNITS);
  IF CALC_LENGTH(iWIDTH_UNITS, iWIDTH) * iPIECES <= 4 THEN
    SET vLINEAR = MULTIPLIER_LINEAR_FEET(4) * CALC_LENGTH(iLENGTH_UNITS,iLENGTH);
  ELSEIF CALC_LENGTH(iWIDTH_UNITS, iWIDTH)*iPIECES > 4 AND CALC_LENGTH(iWIDTH_UNITS, iWIDTH)<= 4 THEN
    SET vLINEAR = MULTIPLIER_LINEAR_FEET(CALC_LENGTH(iWIDTH_UNITS, iWIDTH)*iPIECES) * CALC_LENGTH(iLENGTH_UNITS,iLENGTH_1);
  ELSEIF CALC_LENGTH(iWIDTH_UNITS, iWIDTH) > 4 THEN
    SET vLINEAR = iPIECES * CALC_LENGTH(iLENGTH_UNITS,iLENGTH_1);
  END IF;
  IF TOTAL_LINEAR(iORID) >= 10 THEN
    UPDATE TLDTL SET
      CUBE = vLINEAR * 100,
      WHERE ORDER_ID = iORID;
  ELSEIF TOTAL_LINEAR(iORID) < 10 THEN
    UPDATE TLDTL SET
      CUBE = vCUBE
      WHERE ORDER_ID = iORID;
  END IF;
END

0 个答案:

没有答案