MySQL Stored Procedure example. You cannot use begin end in if else. Otherwise, an Error Code: 1064 will be reported.

Source: Internet
Author: User
Tags stored procedure example

MySQL Stored Procedure example. You cannot use begin end in if else. Otherwise, an Error Code: 1064 is reported to solve the Error Code: 1064You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near. the error is reported because the if else statement in mysql procedure uses the begin end statement and is OK if it is removed. [SQL] DELIMITER $ USE 'sportgbmj '$ DROP PROCEDURE IF EXISTS 'SP _ web_addmiddayrank' $ CREATE DEFINER = 'root' @ '%' PROCEDURE 'SP _ web_addmiddayrank '() BEGIN/* revision record: Supervisor version revised by revision date revision description 2013-06-15 query current Am-Am rankings this sp is executed after the end of the current competition prerequisites: 1: must complete 10 (inclusive) bureaus or above in one field */DECLARE I _date DATE; DECLARE I _starttime TIME; DECLARE I _endtime TIME; SET I _date = NOW (); SET I _endtime = NOW (); IF (I _endtime> '22: 30') THEN <strong> <span style = "color: # ff0000; "> BEGIN </span> </strong>/* night arena */SET I _starttime = '21: 30'; SET I _endtime = '22: 30 '; <strong> <span style = "color: # ff0000;"> END </span> </strong> ELSE <span style = "color: # ff0000; "> <strong> BEGIN </strong> </span>/* midday field */SET I _starttime = '12: 30'; SET I _endtime = '13: 30 '; <span style = "color: # ff0000;"> <strong> END </strong> </span> end if; create temporary table tmp_rank (id int not null AUTO_INCREMENT -- auto-increment, userid INT -- User id, beans INT -- bean summary, rounds TINYINT -- number of Bureaus summary, posttime TIME -- TIME (the player's last TIME in the game) ENGINE = MYISAM; insert into tmp_rank (userid, beans, rounds, posttime) SELECT userid, SUM (case when consume> 0 THEN consume ELSE 0 END) beans, COUNT (userid) rounds, MAX (posttime) AS posttime FROM score as s inner join scorelist as sl on s. pid = SL. pid WHERE roomid IN ('20140901') AND (postdate = I _date AND posttime> = '12: 30: 00' AND posttime <= '13: 30: 00 ') group by userid HAVING (rounds> = 10) order by beans DESC, maxtime asc limit 500;/* INSERT a table */insert into hf_playranklist (userid, rank, beans, rounds, postdate, posttime) SELECT userid, beans, rounds, I _date, posttime FROM tmp_rank;/* INSERT prize table */INSERT INTO hf_prizelist (userid, STATUS, prizeid, receivetime, postdate) SELECT userid, 0, (case when id> = 11 THEN 4 WHEN (id> = 3 AND id <= 10) THEN 3 WHEN id = 2 THEN 2 WHEN id = 1 THEN 1 END) AS prizeid, beans, rounds, posttime FROM tmp_rank as r where rank> = 30; END $ DELIMITER;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.