I am new to Mysql and I am trying to write mysql stored procedure with transaction.but I am getting error:
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 21
Here is my procedure:
DELIMITER $$
CREATE PROCEDURE InsertVote(IN image_param VARCHAR(30),
IN user_id_param INT,
IN vore_char CHAR(1)
)
Begin
START TRANSACTION;
IF vote_char="A" THEN
UPDATE img_options SET A_result=(A_result+1) WHERE image=image_param;
ELSE IF vote_char="B" THEN
UPDATE img_options SET B_result=(B_result+1) WHERE image=image_param;
ELSE IF vote_char="C" THEN
UPDATE img_options SET C_result=(C_result+1) WHERE image=image_param;
ELSE
UPDATE img_options SET D_result=(D_result+1) WHERE image=image_param;
END IF;
Insert into WATCH_FEED_EVEN values(image_param,user_id_param);
select * from img_options where image=image_param;
COMMIT; <---Line No 21
END $$
DELIMITER ;
I tried to solve this one for more than 2 hours but I couldn't able to do this.Can anyone help me?
Related
I'm trying to add a trigger that should automatically update a datetime column only if is not present a SQL variable. The trigger code is the following
delimiter |
CREATE TRIGGER update_sync_date
BEFORE UPDATE ON posts
FOR EACH ROW
BEGIN
IF #disable_sync_date_update IS NULL OR #disable_sync_date_update <> 1 THEN
SET new.sync_date = CURRENT_TIMESTAMP
END IF
END|
delimiter ;
The error that I recieve is
#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 'END IF
END' at line 7
Thanks for helping
I've found the solution, here is the correct code:
delimiter |
CREATE TRIGGER update_sync_date
BEFORE UPDATE ON posts
FOR EACH ROW
BEGIN
IF #disable_sync_date_update IS NULL OR #disable_sync_date_update <> 1 THEN
SET new.sync_date = CURRENT_TIMESTAMP;
END IF;
END|
delimiter ;
I just want to create trigger in my sql but some error happened
this is the code
CREATE TRIGGER delete_santri_in_kamar
AFTER UPDATE ON
santri
FOR EACH ROW
BEGIN
DECLARE stat INT
SET stat = select status FROM santri WHERE id_santri=new.id_santri
IF (stat = 0) THEN
DELETE FROM santri_kamar_asrama WHERE id_santri=new.id_santri
END IF
END
and this is the error message
#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 'SET stat = select status FROM santri WHERE id_santri=new.id_santri
IF (stat =' at line 7
please help me
Add semicolons after the statements and change default delimiter(;) before the code of create trigger. Otherwise it will give
SQL Error(1064): You have an error in your SQL Syntax;
After the create trigger code make ; as default delimiter
DELIMITER $$
CREATE TRIGGER delete_santri_in_kamar
AFTER UPDATE ON
santri
FOR EACH ROW
BEGIN
DECLARE stat INT;
SET stat = (select status FROM santri WHERE id_santri=new.id_santri);
IF (stat = 0) THEN
DELETE FROM santri_kamar_asrama WHERE id_santri=new.id_santri;
END IF;
END
$$
DELIMITER ;
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.
I want to do write a stored procedure using MysQL, that let me insert, update or delete using parameters, into persona's table, who has the fields id_persona, nombres, apellidos & edad; so can you give me an idea why this is wrong about my stored procedure?
DELIMITER $$
DROP PROCEDURE IF EXISTS guardarPersona$$
CREATE PROCEDURE persona(input_id_persona INT, input_nombres VARCHAR(100), input_apellidos VARCHAR(100), input_edad INT, input_accion VARCHAR(15))
BEGIN
IF (input_accion='guardar') THEN
INSERT INTO `persona`(`nombres`, `apellidos`, `edad`) VALUES (input_nombres,input_apellidos,input_edad);
ELSEIF (input_accion='modificar') THEN
UPDATE `persona` SET `nombres`=input_nombres,`apellidos`=input_apellidos,`edad`=input_edad WHERE id_persona = input_id_persona;
ELSEIF (input_accion='eliminar') THEN
DELETE FROM `persona` WHERE id_persona = input_id_persona;
ELSE
mysql_error();
END IF;
END $$
DELIMITER ;
This is the mysql error....
MySQL ha dicho: Documentación
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 '();
END IF;
END' at line 10
mysql_error() function is using in API.
For get data of error inside stored procedure you should use SHOW ERRORS;
...
ELSE
SHOW ERRORS;
END IF;
....
The sql i wrote
**delimiter |
CREATE
DEFINER=CURRENT_USER
TRIGGER set_profiletype_after_insert BEFORE INSERT ON trl_translator FOR EACH ROW
BEGIN
UPDATE trl_profile SET trl_profile.type = 'translator' WHERE trl_profile.profile_id = NEW.translator_id
END
|
delimiter ;**
The error given
[SQL]
**CREATE
DEFINER=CURRENT_USER
TRIGGER set_profiletype_after_insert BEFORE INSERT ON trl_translator FOR EACH ROW
BEGIN
UPDATE trl_profile SET trl_profile.type = 'translator' WHERE trl_profile.profile_id = NEW.translator_id
END
;
[Err] 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' at line 6**
How to solve this ? where is the mistake i do ?
It looks like you simply need to terminate your UPDATE statement with a semicolon.
Try this code
delimiter |
CREATE
DEFINER=CURRENT_USER
TRIGGER set_profiletype_after_insert BEFORE INSERT ON trl_translator FOR EACH ROW
BEGIN
UPDATE trl_profile SET trl_profile.type = 'translator' WHERE trl_profile.profile_id = NEW.translator_id;
END;|
delimiter ;