MySQL function returns string error - mysql

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

Related

SQL syntax error: MySQL server RETURNS timestamp deterministic BEGIN

I am getting the following error:
1064 - SQL syntax; MySQL server RETURNS timestamp deterministic BEGIN DECLARE
dt_act timestamp; sele' at line 1
This is my code:
DROP FUNCTION IF EXISTS NewProc;
DELIMITER //
CREATE FUNCTION NewProc(f_test varchar)
RETURNS timestamp deterministic
BEGIN
DECLARE dt_act timestamp;
select cast((case
when str_to_date(activation_date,'%d-%M-%Y') is not null then date_format(str_to_date(activation_date,'%d-%M-%Y'),'%Y-%m-%d')
when str_to_date(activation_date,'%d-%m-%Y') is not null then date_format(str_to_date(activation_date,'%d-%m-%Y'),'%Y-%m-%d')
ELSE
date_format(str_to_date(activation_date,'%Y-%M-%d'),'%Y-%m-%d')
end) as timestamp ) into dt_act from abc where phone_no =f_test;
RETURN dt_act;
END //
DELIMITER ;
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 ') RETURNS timestamp deterministic BEGIN DECLARE dt_act timestamp; sele' at line 1

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 ;

Error in MySQL stored procedure

I have a simple stored procedure:
DELIMITER $$
CREATE PROCEDURE `my_proc`(IN mac VARCHAR(12), IN my_field1 INTEGER)
BEGIN
UPDATE mytable SET field1 = my_field1 WHERE mac_address = mac;
END$$
This gives me:
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 4
Line 4 is "BEGIN"
How is that possible?

how to create a function in MySQL5?

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 ;

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