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 ;
Related
I am trying to create a procedure in MYSQL which just selects all the rows from a table.
DELIMITER $$
CREATE PROCEDURE getAll_Temps()
BEGIN
SELECT * from temp1
END $$
But I am getting this error,
ERROR 1064 (42000): 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 1.
Try below query.You miss the ; at the end of the query.
DELIMITER $$
CREATE PROCEDURE getAll_Temps()
BEGIN
SELECT * from temp1;
END $$
Hope this helpful to you.
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 am trying run a stored procedure but its getting failed due to IF condition.I have tried with different ways still no success. can anyone let me know, how to use IF condition in the stored procedure.
DELIMITER $$
USE `testdb`$$
DROP PROCEDURE IF EXISTS `change_parent`$$
CREATE DEFINER=`root`#`localhost` PROCEDURE `change_parent`(
IN new_parent BIGINT(20),
IN folder__id BIGINT(20)
)
BEGIN
SELECT
directory_path,nav_depth,id
INTO
#dirpath,#depth,#parent
FROM folders
WHERE id = new_parent;
UPDATE folders
IF (folder__id != #parent) THEN
SET directory_path = CONCAT(#dirpath,'/',title),
nav_depth = #depth+1,
parent__id = #parent
END IF;
WHERE id = folder__id;
END$$
DELIMITER ;
Here is the error message
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: 'IF folder__id != #parent THEN SET directory_path = CONCAT(#dirpath,'/',title' at line 13
IF (folder__id != #parent) THEN
UPDATE folders
SET ...
WHERE id = folder__id;
END IF;
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;
....
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.