An error is reported when a mysql trigger is created.

Source: Internet
Author: User
DROPTABLEifEXISTStb; CREATETABLEtb (BHCHAR (16), contentVARCHAR (20), 'date' DATETIME, valINT); values (8) DECLAREbh_idCHAR (16) DECLAREnumberINT (1) values... mysql

Drop table if EXISTS tb;
Create table tb (bh char (16), content VARCHAR (20 ),DateDATETIME, val INT );

Create trigger tri_NewBH before insert on tb
FOR EACH ROW
BEGIN
DECLARE dt CHAR (8)
DECLARE bh_id CHAR (16)
DECLARE number INT (1)
DECLARE new_bh VARCHAR (16)

SET dt = DATE_FORMAT (CURDATE (), '% Y % m % d') select max (BH) INTO bh_id FROM tb where bh like concat (dt,' % ') IF bh_id = ''OR bh_id is null then set new_bh = CONCAT (dt, '123') else set number = RIGHT (bh_id, 8) + 1 SET new_bh = RIGHT (CONCAT ('20140901', number), 8) SET new_bh = CONCAT (dt, new_bh) end if set new. BH = new_bh END

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: info-contact@alibabacloud.com 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.