I have the following procedure (one of my first procedures in MySQL):
DROP PROCEDURE IF EXISTS usp_deposit_money;
DELIMITER $$
CREATE PROCEDURE usp_deposit_money(IN account_id INT,IN money_amount
DECIMAL(19,4))
BEGIN
START TRANSACTION;
UPDATE accounts
SET accounts.balance = accounts.balance + money_amount
WHERE accounts.id = account_id;
IF money_amount <= 0
THEN
ROLLBACK;
ELSE
COMMIT;
END IF;
END $$
DELIMITER ;
But I get the following error message:
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 'DELIMITER $$
CREATE PROCEDURE usp_deposit_money(IN account_id INT,IN money_amou' at line 1
Related
I try to create a trigger but I get this error after executing the SQL:
# 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 'DECLARE temp INT' at line 4
Here is my trigger:
CREATE TRIGGER hesap
AFTER INSERT ON uber
DECLARE temp INT;
BEGIN IF uber.il='ANKARA' THEN
temp=5+(uber.mesafe*0.5);
ELSEIF uber.il='ISTANBUL' THEN
temp=10+(uber.mesafe*0.5);
ELSEIF uber.il='IZMIR' THEN
temp=3+(uber.mesafe*0.5);
END IF;
INSERT INTO fatura VALUES(uber.uid,temp)
END;
There is some syntax error as I identified check out the below code:
delimiter $$
CREATE TRIGGER hesap
AFTER INSERT ON uber FOR EACH ROW
BEGIN
DECLARE temp integer;
IF new.il = 'ANKARA' THEN
temp= 5+(uber.mesafe*0.5);
ELSEIF new.il='ISTANBUL' THEN
temp=10+(uber.mesafe*0.5);
ELSEIF new.il='IZMIR' THEN
temp=3+(uber.mesafe*0.5);
END IF;
INSERT INTO fatura VALUES(new.uid,temp);
END
delimiter ;
DELIMITER //
DROP PROCEDURE IF EXISTS pad_fato_to_tad_fato//
CREATE PROCEDURE pad_fato_to_tad_fato(IN IDFATO BIGINT, IN UCI BIGINT)
BEGIN
INSERT INTO tad_fato (FAT_UCI, FAT_DESCRICAO,
FAT_DATA_CIENCIA_AUTORIDADE,
FAT_CADASTRANTE, FAT_DATA_CAD)
SELECT FAT_UCI, FAT_DESCRICAO, FAT_DATA_CIENCIA_AUTORIDADE,
FAT_CADASTRANTE, FAT_DATA_CAD
FROM pad_fato WHERE (FAT_ID = IDFATO);
END//
BEGIN
UPDATE tad_termo_de_ajustamento SET TAD_STATUS_ID="2" WHERE (TAD_FK_PRE_UCI = UCI);
END//
DELIMITER ;
Error (12,1): 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 UPDATE tad_termo_de_ajustamento SET TAD_STATUS_ID="2" WHERE (TAD_FK_PRE_UCI=UCI) at line 2
You have double "END" word after each query.
And not pretty formatted code :)
DELIMITER //
DROP PROCEDURE IF EXISTS pad_fato_to_tad_fato//
CREATE PROCEDURE pad_fato_to_tad_fato(IN IDFATO BIGINT, IN UCI BIGINT)
BEGIN
INSERT INTO tad_fato (
FAT_UCI,FAT_DESCRICAO,
FAT_DATA_CIENCIA_AUTORIDADE,
FAT_CADASTRANTE,FAT_DATA_CAD
)
SELECT
FAT_UCI,
FAT_DESCRICAO,
FAT_DATA_CIENCIA_AUTORIDADE,
FAT_CADASTRANTE,
FAT_DATA_CAD
FROM pad_fato
WHERE (FAT_ID=IDFATO);
UPDATE tad_termo_de_ajustamento
SET
TAD_STATUS_ID="2"
WHERE (TAD_FK_PRE_UCI=UCI);
END//
DELIMITER ;
simple question
this is the code to creat a simple stored procedure
DELIMITER $$
CREATE PROCEDURE `check_mobile_sp`(
IN mobile_numberEntered VARCHAR(12)
)
BEGIN
SELECT id, mobile_number, `date`
from users
WHERE mobile_number = mobile_numberEntered;
END $$
DELIMITER ;
and this is the 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 'DELIMITER' at line 1
try placing // instead of $$:
DELIMITER //
CREATE PROCEDURE `check_mobile_sp`(
IN mobile_numberEntered VARCHAR(12)
)
BEGIN
SELECT id, mobile_number, `date`
from users
WHERE mobile_number = mobile_numberEntered;
END //
DELIMITER ;
I'm trying to create a procedure but its get an error.
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 4.
Line 4 is "INSERT INTO TB...."
DROP PROCEDURE IF EXISTS simpleproc;
CREATE PROCEDURE simpleproc (IN p_cd_empresa INT, IN p_cd_servico INT, IN p_cd_concessionaria VARCHAR (100))
BEGIN
IF p_cd_servico = 1 OR p_cd_servico = 3 OR p_cd_concessionaria = 'GESTAO' THEN
INSERT INTO TB_EMPRESA_IMPORTAR VALUES (p_cd_empresa, p_cd_servico, p_cd_concessionaria);
END IF;
END;
You forgot to put another delimiter than ; for multi-statement procedures / functions.
DELIMITER $$
DROP PROCEDURE IF EXISTS simpleproc;
CREATE PROCEDURE simpleproc (IN p_cd_empresa INT, IN p_cd_servico INT, IN p_cd_concessionaria VARCHAR (100))
BEGIN
IF p_cd_servico = 1 OR p_cd_servico = 3 OR p_cd_concessionaria = 'GESTAO' THEN
INSERT INTO TB_EMPRESA_IMPORTAR VALUES (p_cd_empresa, p_cd_servico, p_cd_concessionaria);
END IF;
END;
DELIMITER ;
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;
....