Error when creating mysql trigger - mysql

I want to create a trigger to set the value of f_IrrMinCurr based on the IrrMinCurr. This is what I wrote.
CREATE TRIGGER Fuzzification BEFORE INSERT ON fuzzyanalysis
FOR EACH ROW
BEGIN
IF NEW.IrrMinCurr < 200.0 THEN
SET NEW.f_IrrMinCurr = 'H';
ELSE
SET NEW.f_IrrMinCurr = null;
END IF;
END;
I'm getting the error,
Error
SQL query:
CREATE TRIGGER Fuzzification BEFORE INSERT ON fuzzyanalysis
FOR EACH ROW
BEGIN
IF NEW.IrrMinCurr < 200.0 THEN
SET NEW.f_IrrMinCurr = null;
MySQL said: Documentation
#1064 - 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 '' at line 5
Can anyone please help me to solve this.

Related

mySQL IF statement in trigger error in Maria DB

This code works fine in fiddle to create the trigger.
https://topanswers.xyz/databases?q=1929
However, I have the exact same code on my phpMyaAmin SQL command, but on phpMyAdmin return this in the create trigger section.
CREATE TRIGGER Update_trigger
BEFORE INSERT ON product_price
FOR EACH ROW
BEGIN
IF (NEW.product_id = 'P9999')
THEN SET NEW.product_id = 'name99', NEW.value_price = 999;
END IF;
IF (NEW.product_id = 'P7777')
THEN SET NEW.product_name = 'name77', NEW.value_price = 777;
END IF;
END;
#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 ‘’ at line 8
My phpMyAdmin Server version: 10.4.21-MariaDB - mariadb.org binary distribution
Could anyone help, please?

Error MySQL Creating Trigger

I'm getting an odd error every time I try to create one UPDATE trigger into one of my tables...
The Trigger:
CREATE TRIGGER upd_data_nascimento BEFORE UPDATE ON pfi_pessoa_fisica
FOR EACH ROW
BEGIN
IF OLD.date_of_birth = '0000-00-00' THEN
SET NEW.date_of_birth = NULL;
END IF;
END;
And the error:
Error SQL (1064): 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 '' at line 5
Any ideas?
Make sure you are using delimiter
CREATE TRIGGER upd_data_nascimento BEFORE UPDATE ON abc_table
FOR EACH ROW
BEGIN
IF OLD.date_of_birth = '0000-00-00' THEN
SET NEW.date_of_birth = NULL;
END IF;
END
If you are executing it in PHPMyAdmin then set the delimiter to # or something else. And then execute it will work fine I have tested it with above code.

Error 1064 during trigger creation

I want to create a trigger on one of the tables, it's very simple, just to set one value - but I always get error 1064
CREATE TRIGGER `trigger_TEST` BEFORE INSERT ON `TEST_table`
FOR EACH ROW
BEGIN
IF NEW.as_src = 13335 THEN
SET NEW.peer_as_src = 13335;
END IF
END
And get this error:
Error SQL (1064): 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 '' at line 5
Any idea why ?
You need to change the default delimiter
delimiter |
CREATE TRIGGER `trigger_TEST` BEFORE INSERT ON `TEST_table`
FOR EACH ROW
BEGIN
IF NEW.as_src = 13335 THEN
SET NEW.peer_as_src = 13335;
END IF;
END
|
delimiter ;
Otherwise the statement will end at the first ; which would make the trigger definition incomplete.

SQL syntax error in trigger

Can someone tell me what this sql does not work? Where is the syntax error?
SET NEW.`modified` = CURTIME() WHERE `id` = NEW.id;
Error:
One or more errors have occured while processing your request:
The following query has failed:
CREATE DEFINER=`root`#`localhost` TRIGGER `event_name`
BEFORE UPDATE ON `clients`
FOR EACH ROW
SET NEW.`modified` = CURTIME() WHERE `id` = NEW.id;
MySQL said: #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 'WHERE id = NEW.id' at line 1
Image shows the error
http://s23.postimg.org/rhsf2x1tn/screenshot.png
You don't need the where condition to specify the row being changed.
For every row being updated, you set the specific column value. See the example below as well as the quoted reference.
Quoting/Referencing from here:
DELIMITER |
CREATE TRIGGER event_name BEFORE UPDATE ON clients
FOR EACH ROW
BEGIN
SET NEW.date_modify = NOW();
END;
|
DELIMITER ;

How to create a trigger to set empty stings to null before insert with SQL?

I'm using phpmyadmin and I can't figure to how to get it to automatically set empty strings to null while importing data, so I'm trying to write a trigger to do it.
My trigger will eventually have to include many more fields than this, but this is my test run trigger, which is not working:
create trigger test1
before insert
on hvi
for each row
begin
if new.`Amt` = ' ' then
set new.`Amt` = null
end if;
end;
I get this error:
MySQL said: Documentation # 1064 - 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 'end if' at
line 8
What am I doing wrong?
if new.`Amt` = ' ' then
set new.`Amt` = null ;
end if;