MySQL多个条件判断示例


  本文标签:MySQL多个条件判断

  MySQL多个条件判断是怎样的呢?下面就为您举例说明MySQL多个条件判断,希望对您学习MySQL多个条件判断方面能够有所启迪  。

  1. use industry_finance;   
  2. DELIMITER //   
  3. drop procedure if exists updateCursor //   
  4. CREATE PROCEDURE updateCursor()   
  5. BEGIN   
  6. declare id varchar(20);   
  7. declare month varchar(20);   
  8. declare season varchar(20);   
  9. declare cur1 CURSOR FOR SELECT ID_,month_ FROM t_industry_finance_instance;   
  10. OPEN cur1;   
  11. FETCH cur1 INTO id,month;   
  12. WHILE (id is not null ) DO   
  13. if(month=01||month=02||month=03) THEN set season=1;   
  14. end if;   
  15. if(month=04||month=05||month=06) THEN set season=2;   
  16. end if;   
  17. if(month=07||month=08||month=09) THEN set season=3;   
  18. end if;   
  19. if(month=10||month=11||month=12) THEN set season=4;   
  20. end if;   
  21. update t_industry_finance_instance set seasonseason_=season where ID_=id;   
  22. FETCH cur1 INTO id,month;   
  23. END WHILE;   
  24. CLOSE cur1;   
  25. END;//   
  26. DELIMITER ;   
  27. call updateCursor();