MySQL storage function error [Err] 1064 debugging record, err1064

Source: Internet
Author: User

MySQL storage function error [Err] 1064 debugging record, err1064
1. An error is reported when a user creates a storage function.
Create definer = 'root' @ 'localhost' FUNCTION 'stuff '(
F_old varchar (1000), f_start int, f_length int, f_replace varchar (1000)
) RETURNS varchar (2000) CHARSET utf8
BEGIN
Return replace (f_old, substring (f_old, f_start, f_length), f_replace );
END


[SQL] create FUNCTION f_Int2IP (ip bigint) RETURNS varchar (15)
BEGIN
DECLARE re varchar (15) default '';
SELECT concat ('.', CAST (ip/id as char), ip % id into re, ip
From (
SELECT 16777216 as id
Join all select 65536
Join all select 256
Union all select 1);
Set
Return stuff (re, 1,1 ,'');
END

The following error is reported:
[Err] 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 'varchar )), ip % id into re, ip
From (
SELECT 16777216 as id
Union all sel 'at line 4


2. Check whether the function is Enabled:
Check whether log_bin_trust_function_creators is enabled.
Mysql> show variables like '% func % ';
+ --------------------------------- + ------- +
| Variable_name | Value |
+ --------------------------------- + ------- +
| Log_bin_trust_function_creators | OFF |
+ --------------------------------- + ------- +
1 row in set (0.00 sec)


If the Value of Value is OFF, You need to enable it.
Mysql> set global log_bin_trust_function_creators = 1;
Query OK, 0 rows affected (0.00 sec)


Mysql> show variables like '% func % ';
+ --------------------------------- + ------- +
| Variable_name | Value |
+ --------------------------------- + ------- +
| Log_bin_trust_function_creators | ON |
+ --------------------------------- + ------- +
1 row in set (0.00 sec)
Mysql>


Iii. Analysis
For mysql storage functions, special DELIMITER should be used for distinguishing, and select... into... has been assigned a value. set is redundant, so the modification is as follows:
DELIMITER $
Drop function if exists test. stuff $
Create function test. 'stuff '(
F_old VARCHAR (1000), f_start INT, f_length INT, f_replace VARCHAR (1000)
) Returns varchar (2000)
BEGIN
Return replace (f_old, SUBSTRING (f_old, f_start, f_length), f_replace );
END $


DELIMITER $
Drop function if exists test. f_Int2IP $
Create function 'test'. 'f _ int2ip' (ip BIGINT)
Returns varchar (2000)
BEGIN
DECLARE re VARCHAR (2000) DEFAULT '';
Select concat ('.', CAST (ip/id as char) AS restr, ip % id INTO re, ip
FROM (
SELECT 16777216 AS id
Join all select 65536
Join all select 256
Union all select 1);
RETURN stuff (re, 1,1 ,',');
END $
DELIMITER;


4. Execute the following operations. All operations are OK.
Mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-

Database changed
Mysql> DELIMITER $
Mysql> drop function if exists test. stuff $
Query OK, 0 rows affected (0.00 sec)


Mysql> create function test. 'stuff '(
-> F_old VARCHAR (1000), f_start INT, f_length INT, f_replace VARCHAR (1000)
->) Returns varchar (2000)
-> BEGIN
-> Return replace (f_old, SUBSTRING (f_old, f_start, f_length), f_replace );
-> END $
Query OK, 0 rows affected (0.01 sec)


Mysql>
Mysql> DELIMITER $
Mysql> drop function if exists test. f_Int2IP $
Query OK, 0 rows affected (0.00 sec)


Mysql> create function 'test'. 'f _ int2ip' (ip BIGINT)
-> Returns varchar (2000)
-> BEGIN
-> DECLARE re VARCHAR (2000) DEFAULT '';
-> Select concat ('.', CAST (ip/id as char) AS restr, ip % id INTO re, ip
-> FROM (
-> SELECT 16777216 AS id
-> Union all select 65536
-> Union all select 256
-> Union all select 1);
-> RETURN stuff (re, 1,1 ,',');
-> END $
Query OK, 0 rows affected (0.00 sec)


Mysql> DELIMITER;
Mysql>


Add a function with an int value.
Delimiter $
Create function first_func (param1 varchar (5), parmam2 varchar (5), param3 varchar (10 ))
RETURNS TINYINT
BEGIN
RETURN 1;
END

PS: mysql storage functions or stored procedures have tools that can be directly debugged. Therefore, you need to analyze them carefully and try to use as few stored procedures or stored functions as possible in applications.
MySql encountered the following ERROR during storage creation: ERROR 1064 (42000 ):

Your SQL statement is wrong. When you see the 1064 error, your SQL statement has a syntax error.

[Err] 1064 in mysql. What should I do? Urgent

"UserId" number, ------------------ "userId" int,
Mysql uses int

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.