我想用mysql生成一个类似“b45”的代码。生成从'a0'开始,以'y99'结束,但不知怎么的,有一个问题,请我需要帮助我的代码
CREATE TRIGGER oeuvre_code BEFORE INSERT ON oeuvres
BEGIN
IF NOT EXISTS(select * from oeuvres) THEN
SET @code2 ='A0';
ELSE
SET @test = (select code from oeuvres LIMIT 1);
SET @char =(select left (@test,1));
SET @nbr = select substr(@test,2);
if @char!='Z' AND @nbr+0 <99 THEN
set @char2 = select (ASCII(@char)+1);
set @nbr2 = @nbr+1;</i>
END IF;
set @code2=@char2+@nbr2;
INSERT INTO oeuvres VALUES(NEW.Id,NEW.Toile,NEW.Description,NEW.Prix,NEW.Date,NEW.Etat,@code2);
END IF;
END;
问题是:
Error
SQL query: Documentation
CREATE TRIGGER oeuvre_code BEFORE INSERT ON oeuvres
BEGIN
IF NOT EXISTS(select * from oeuvres) THEN
SET @code2 ='A0'
MySQL said: Documentation
# 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'BEGIN
IF NOT EXISTS(select * from oeuvres) THEN
SET @code2' at line 2
我得到的问题的图片
暂无答案!
目前还没有任何答案,快来回答吧!