how to create a function in MySQL5? - mysql

The question is what's happening?
CREATE FUNCTION HiWorld() RETURNS VARCHAR(20)
BEGIN
RETURN 'Hi';
END;
RESULT: #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

delimiter //
CREATE FUNCTION hiworld()
RETURNS VARCHAR(20) DETERMINISTIC
begin
return 'Hello';
end//
delimiter ;

Related

How to fix NOT NULL error (error code: 1064)?

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$$

Query to return a table generates SQL ERROR (1064): Error in syntax

I'm trying to create a function, but keep getting the error message that
SQL ERROR (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 3.
DELIMITER $$
DROP FUNCTION IF EXISTS mysql.HelpMePlz$$
CREATE FUNCTION mysql.HelpMePlz(input VARCHAR(255) ) RETURNS VARCHAR(255) BEGIN
DECLARE result VARCHAR(255);
SELECT name into result
FROM tb_company
WHERE company_info = input
LIMIT 3
RETURN result;
END $$
DELIMITER ;

MySQL function returns string error

I have create this function
DELIMITER $$
CREATE FUNCTION func05(x1 int)
RETURNS varchar(100) CHARSET utf8
READS SQL DATA
BEGIN
RETURN (SELECT txt FROM strutture INNER JOIN dizionario ON dz_nome = idtxt WHERE idls = x1 LIMIT 0,1)
END$$
DELIMITER ;
But returns this 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 'END' at line 6

mysql stored procedure syntax error at line 9

delimiter //
create PROCEDURE usp_AlterIsCanceled (p_requestid longtext)
BEGIN
update requests
set IsCanceled=1
where id=p_requestid
end
//
delimiter;
/* SQL 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 'end' at line 9 */
add semicolumn ;
DELIMITER $$
create PROCEDURE usp_AlterIsCanceled (p_requestid longtext)
BEGIN
update requests
set IsCanceled=1
where id=p_requestid;
END $$
delimiter;

Can any one suggest me how to resolve this problem: Error Code : 1064 in MY SQL 5.5 ver

DELIMITER $$;
DROP FUNCTION IF EXISTS tonumeric $$;
CREATE FUNCTION tonumeric() returns numeric
BEGIN
declare num numeric;
set num = to_number('12');
return num;
END$$
DELIMITER; $$
When I executed this function, I am facing 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 'IF EXISTS tonumeric' at line 1
(0 ms taken)
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 ';
CREATE FUNCTION tonumeric() returns numeric
BEGIN
declare num numeric;
set num' at line 1
(0 ms taken)
Thanks
How about this:
DELIMITER $$
DROP FUNCTION IF EXISTS tonumeric $$
CREATE FUNCTION tonumeric() returns numeric
BEGIN
declare num numeric;
set num = to_number('12');
return num;
END$$
DELIMITER ;
Delimiter is a special command, in that you shouldn't terminate it with a ; -- you're actually setting the delimiter to "$$;", not "$$".