2

我是编写存储过程的新手,我似乎在这个过程中找不到错误。错误标记在 where 部分附近。

我尝试寻找一个基于 if 条件完成设置的示例,但我似乎找不到这样的示例。谁能指出我的错误?

DELIMITER $$

CREATE PROCEDURE `incubation`.`bt_voice_modification` 
    (in input_slot varchar(45),in input_port varchar(45))
BEGIN
    SET @SVLAN_STH:=1000;
    SET @SVLAN_DTH:=999;
    SET @CVLAN_DTH:=1000;
    SET @FLOW_INSTANCE:=1;

    UPDATE one_2_one_table
        SET  L2S_USER_FLOW_INSTANCE = @FLOW_INSTANCE := @FLOW_INSTANCE+1;
        SET  L2S_NW_SLOT = input_slot;
        SET  L2S_NW_PORT = input_port;
        IF STH_DTH = 'STH' then
            set  L2S_NW_SVLAN = @SVLAN_STH :=@SVLAN_STH + 1;
        ELSE 
            set  L2S_NW_SVLAN = @SVLAN_DTH ;
            set  L2S_NW_CVLAN = @CVLAN_DTH :=@CVLAN_DTH + 1;
        END if;
        WHERE IPDSLAM_USER_SLOT = 2 AND L2S_USER_TYPE like "%gplt%";

END
4

1 回答 1

1

UPDATE您的代码表明您对语句的工作方式或确切语法没有非常清楚的了解。当您放置 a;时,它标志着 (UPDATE) 语句的结束。语法是 - 对于一个表:

UPDATE tableX

  SET columnA = what_value_should_columnA-get ,
      columnB = what_value_should_columnB_get ,
      ...
      columnX = what_value_should_columnX_get 

WHERE (conditions that restrict the rows that will be affected)

ORDER BY SomeColumn ;   --- this can be used in MySQL only. Standard SQL 
                        --- (and most DBMS) do not allow ORDER BY clause in
                        --- UPDATE statements. Since you are using variables
                        --- and the order of updating affects the updated values,
                        --- it's essential that you include an ordering.

所以,你UPDATE会是这样的:

UPDATE one_2_one_table
    SET  L2S_USER_FLOW_INSTANCE = @FLOW_INSTANCE := @FLOW_INSTANCE+1 ,
         L2S_NW_SLOT = input_slot,
         L2S_NW_PORT = input_port,
         L2S_NW_SVLAN = CASE WHEN STH_DTH = 'STH'
                               THEN @SVLAN_STH := @SVLAN_STH + 1
                               ELSE @SVLAN_DTH 
                        END ,
         L2S_NW_CVLAN = CASE WHEN STH_DTH = 'STH'
                               THEN L2S_NW_CVLAN
                               ELSE @CVLAN_DTH := @CVLAN_DTH + 1
                        END

WHERE IPDSLAM_USER_SLOT = 2 
  AND L2S_USER_TYPE like '%gplt%' 

ORDER BY SomeColumn ;
于 2012-06-12T08:11:43.713 回答