我想用mysql生成varchar代码

时间:2018-04-20 01:59:26

标签: mysql variables triggers ascii auto-generate

我想用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

Picture of the problem I get

0 个答案:

没有答案