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 ;
Related
Need some help, my query is:
CREATE PROCEDURE login(usern varchar(255),pass varchar (255))
BEGIN
SELECT * from usuario WHERE username = usern AND password = pass;
END;
Throws
#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 4
As suggested by #nick, when creating a stored routines set delimiter other than default ;
delimiter $$
CREATE PROCEDURE login(usern varchar(255),pass varchar (255))
BEGIN
SELECT * from usuario WHERE username = usern AND password = pass;
END $$
delimiter ;
I cant figure out what is the problem below:
CREATE DEFINER=`root`#`localhost` PROCEDURE `test0`(
$qsFilter VARCHAR(50)
)
BEGIN
SELECT
cs.Customer_First_Name
FROM customer_subscriptions cs
WHERE 1=1 AND ($qsFilter IS NULL OR cs.Customer_First_Name = $qsFilter)
END$$
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 'END'
I think you just need a semicolon, but I would write this as:
DELIMITER $$
CREATE DEFINER=`root`#`localhost` PROCEDURE `test0`(
in_qsFilter VARCHAR(50)
)
BEGIN
SELECT cs.Customer_First_Name
FROM customer_subscriptions cs
WHERE 1 = 1 AND
(in_qsFilter IS NULL OR cs.Customer_First_Name = in_qsFilter);
END$$
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 ;
create procedure update_keyoffice(out p_key varchar(30),out p_hostname varchar(30))
begin
declare p_keyoff varchar(30);
select keyoff into p_keyoff from masterpc where keyoffice = p_key;
if(p_keyoff = p_key) then
insert into keyofficehistory (id,keyoff,hostname,datecreate) values
(null,p_key,p_hostname,now())
end if
end
error
SQL query:
CREATE PROCEDURE update_keyoffice( out p_key varchar( 30 ) , out
p_hostname varchar( 30 ) ) BEGIN DECLARE p_keyoff varchar( 30 ) ;
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 3
While defining stored procedures and triggers, you have to use custom delimiter which, it seems, is missing in your code.
Change your code as below:
delimiter //
-- your stored procedure code here
-- but don't forget to use new delimiter after end statement
end; //
-- now reset delimiter
delimiter ;
Refer to:
CREATE PROCEDURE and CREATE FUNCTION Syntax
I'm trying to add the following stored procedure to my mysql database:
CREATE PROCEDURE logmsg ( _Username VARCHAR(50), _Message VARCHAR(80) )
BEGIN
INSERT INTO chatlogs (sender, message) VALUES (_Username, _Message);
END;
But its failing the query and returning:
#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
I've been searching for about 2 hours on google and cannot find any answer at all.
Any help is greatly appreciated!
While I'm not 100% sure because I can't test on a MySQL server at the moment, I think the problem is in the semicolon. On the line with INSERT you basically end the CREATE PROCEDURE statement, which has incorrect syntax this way. You have to set the delimiter to something else (e.g. //), to be able to use the semicolon in the body of the procedure:
delimiter //
CREATE PROCEDURE logmsg ( _Username VARCHAR(50), _Message VARCHAR(80) )
BEGIN
INSERT INTO chatlogs (sender, message) VALUES (_Username, _Message);
END//
delimiter ;