The following 'CREATE PROCEDURE' statement from MySQL Connector/Python Developer Guide is not working in MySQL Version '5.7.14':
CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT)
BEGIN
SET pProd := pFac1 * pFac2;
END;
Please help fix this error:
Error Code: 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 3
You probably need a delimiter wrapper
DROP PROCEDURE IF EXISTS multiply;
DELIMITER $$
CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT)
BEGIN
SET pProd := pFac1 * pFac2;
END;$$
DELIMITER ;
Related
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
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'm creating procedure which is having two parameters , one is p_cursor of type SYS_REFCURSOR (OUT param) and the other one is p_rank of type INT(IN param). But it showing an error.
DELIMITER $$
CREATE PROCEDURE sp_student(p_cursor OUT SYS_REFCURSOR,p_rank IN INT)
BEGIN
OPEN p_cursor FOR SELECT * FROM student WHERE rank = p_rank;
END$$
DELIMITER ;
the error what I'm getting is,
Error Code : 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 'OUT SYS_REFCURSOR,p_rank IN INT)
BEGIN
OPEN p_cursor FOR SELECT * FROM st' at line 1
I think I'm syntactically wrong for SYS_REFCURSOR.. please check my code and let me realise my mistake.
thanks in advance
mysql doesnt have refcursor like oracle, if u r planning to write a stored procedure that returns multiple rows/result set in mysql just do
DROP procedure IF EXISTS `sample`;
DELIMITER $$
CREATE PROCEDURE `sample`(p_rank IN INT)
BEGIN
select * from MyTable where id=p_rank;
END$$
DELIMITER ;
call sample();
this will return a result set. which u can use.