Home > Database > Mysql Tutorial > mysql创建触发器报错,请高手帮忙看下

mysql创建触发器报错,请高手帮忙看下

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 09:37:37
Original
1239 people have browsed it

mysql

DROP TABLE if EXISTS tb;
CREATE TABLE tb(BH CHAR(16),content VARCHAR(20),date DATETIME,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)

<code>     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,'00000001')     ELSE        SET number = RIGHT(bh_id,8) + 1        SET new_bh =  RIGHT(CONCAT('00000000',number),8)        SET new_bh=CONCAT(dt,new_bh)     END IF     SET NEW.BH = new_bh END</code>
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template