mysql – 在触发器信号语句附近使用concat语法错误
作者:互联网
请帮我学习MySQL 5.6的语法.
出于某种原因,我得到错误:
ERROR 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near '('WRONG SOCIAL: ', new.social);
end if;
if not (new.photo is nul'
尝试运行此SQL代码时:
create table table_social (
sid varchar(250) primary key,
auth char(32) not null,
social integer, -- to be checked by triggers
female boolean,
given varchar(250) not null,
family varchar(250) null,
photo varchar(1000) null, -- to be checked by triggers
place varchar(250) null,
ip varchar(250) not null,
uid integer not null references
table_users(uid) on delete cascade
);
delimiter //
create trigger social_insert_trigger before insert on table_social
for each row begin
if new.social < 0 OR new.social > 6 then
signal sqlstate '45000'
set message_text = concat('WRONG SOCIAL: ', new.social);
end if;
if not (new.photo is null OR new.photo regexp '^https?://') then
signal sqlstate '45000'
set message_text = concat('WRONG PHOTO: ', new.photo);
end if;
end
//
create trigger social_update_trigger before update on table_social
for each row begin
if new.social < 0 OR new.social > 6 then
signal sqlstate '45000'
set message_text = concat('WRONG SOCIAL: ', new.social);
end if;
if not (new.photo is null OR new.photo regexp '^https?://') then
signal sqlstate '45000'
set message_text = concat('WRONG PHOTO: ', new.photo);
end if;
end
//
我尝试删除concat,用双引号替换单引号,将信号线分成两部分(如上所述)和后部 – 但仍然无法找出,有什么问题.
解决方法:
测试此代码:
drop table if EXISTS table_social;
create table table_social (
sid varchar(250) primary key,
auth char(32) not null,
social integer, -- to be checked by triggers
female boolean,
given varchar(250) not null,
family varchar(250) null,
photo varchar(1000) null, -- to be checked by triggers
place varchar(250) null,
ip varchar(250) not null,
uid integer not null references
table_users(uid) on delete cascade
);
delimiter //
create trigger social_insert_trigger before insert on table_social
for each row begin
if new.social < 0 OR new.social > 6 then
set @message_text = concat('WRONG SOCIAL: ', new.social);
signal sqlstate '45000'
set MESSAGE_TEXT = @message_text;
end if;
if not (new.photo is null OR new.photo regexp '^https?://') then
set @message_text = concat('WRONG PHOTO: ', new.photo);
signal sqlstate '45000' set message_text = @message_text;
end if;
end
//
create trigger social_update_trigger before update on table_social
for each row begin
if new.social < 0 OR new.social > 6 then
set @message_text = concat('WRONG SOCIAL: ', new.social);
signal sqlstate '45000'
set message_text = @message_text;
end if;
if not (new.photo is null OR new.photo regexp '^https?://') then
set @message_text = concat('WRONG PHOTO: ', new.photo);
signal sqlstate '45000'
set message_text = @message_text;
end if;
end
//
它不理解SIGNAL SQLSTATE SET message_text中的CONCAT()
标签:mysql-5-6,concat,mysql,syntax,trigger 来源: https://codeday.me/bug/20190806/1599265.html