MySQL儲存函式錯誤[Err] 1064的除錯記錄
一,朋友建立儲存函式報錯。
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
UNION ALL SELECT 65536
UNION ALL SELECT 256
UNION ALL SELECT 1) a;
set
RETURN STUFF(re,1,1,'');
END
報錯如下:
[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
二、檢視建立函式的功能是否開啟:
先看下,log_bin_trust_function_creators有沒有開啟
mysql> show variables like '%func%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
1 row in set (0.00 sec)
如果Value處值為OFF,則需將其開啟。
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>
三,分析
mysql儲存函式,需要特殊的間隔符來區分,還要用DELIMITER來標示,還有select ... into ... 已經賦值了,set就是多餘的,所以修改如下:
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
UNION ALL SELECT 65536
UNION ALL SELECT 256
UNION ALL SELECT 1) a;
RETURN stuff(re,1,1,',');
END$$
DELIMITER ;
四,執行如下,都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 -A
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) a;
-> RETURN stuff(re,1,1,',');
-> END$$
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
mysql>
後補一下帶int的函式
delimiter $$
CREATE FUNCTION first_func(param1 varchar(5),parmam2 varchar(5),param3 varchar(10))
RETURNS TINYINT
BEGIN
RETURN 1;
END
PS:mysql的儲存函式或者儲存過程麼有直接可以除錯的工具,所以需要手工仔細分析檢視,應用中儘量少用儲存過程或者儲存函式。
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
UNION ALL SELECT 65536
UNION ALL SELECT 256
UNION ALL SELECT 1) a;
set
RETURN STUFF(re,1,1,'');
END
報錯如下:
[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
二、檢視建立函式的功能是否開啟:
先看下,log_bin_trust_function_creators有沒有開啟
mysql> show variables like '%func%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
1 row in set (0.00 sec)
如果Value處值為OFF,則需將其開啟。
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>
三,分析
mysql儲存函式,需要特殊的間隔符來區分,還要用DELIMITER來標示,還有select ... into ... 已經賦值了,set就是多餘的,所以修改如下:
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
UNION ALL SELECT 65536
UNION ALL SELECT 256
UNION ALL SELECT 1) a;
RETURN stuff(re,1,1,',');
END$$
DELIMITER ;
四,執行如下,都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 -A
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) a;
-> RETURN stuff(re,1,1,',');
-> END$$
Query OK, 0 rows affected (0.00 sec)
mysql> DELIMITER ;
mysql>
後補一下帶int的函式
delimiter $$
CREATE FUNCTION first_func(param1 varchar(5),parmam2 varchar(5),param3 varchar(10))
RETURNS TINYINT
BEGIN
RETURN 1;
END
PS:mysql的儲存函式或者儲存過程麼有直接可以除錯的工具,所以需要手工仔細分析檢視,應用中儘量少用儲存過程或者儲存函式。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26230597/viewspace-1258484/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL儲存過程除錯工具-dbForge Studio for MySQLMySql儲存過程除錯
- plsqlDevloper 儲存過程的除錯SQLdev儲存過程除錯
- Mysql 的儲存過程和儲存函式MySql儲存過程儲存函式
- Kafka錯誤記錄Kafka
- 群暉儲存池損毀,加上錯誤操作刪除
- 記錄一次資料儲存出錯
- 【儲存】flashcache 使用遇見的錯誤
- 記錄錯誤並繼續執行:錯誤事件記錄子句 --轉事件
- MySql中SUM函式計算錯誤問題MySql函式
- GDB除錯使用記錄除錯
- 記錄一次根據錯誤資訊無法定位錯誤的錯誤
- mysql刪除重複記錄,儲存Id最小的一條MySql
- C++錯誤記錄C++
- SpringMVC錯誤記錄SpringMVC
- MySQL 儲存函式及呼叫MySql儲存函式
- nginx 錯誤除錯Nginx除錯
- rac錯誤除錯除錯
- mysql儲存函過程和儲存函式都屬於儲存程式MySql儲存函式
- mysql和orcale的儲存過程和儲存函式MySql儲存過程儲存函式
- 儲存故障時的ORA-7445錯誤
- Windows 下 PHP 7 中 *getcsv 函式解析 CSV 錯誤的問題記錄WindowsPHP函式
- MySQL的varchar儲存原理:InnoDB記錄儲存結構MySql
- js函式回撥錯誤JS函式
- mysql執行函式出現1418錯誤MySql函式
- (轉)如何oracle除錯儲存過程Oracle除錯儲存過程
- openGauss 支援儲存過程除錯儲存過程除錯
- Mycat+Mysql 插入資料包錯 i[Err] 1064 - partition table, insert must provide ColumnListMySqlIDE
- MySQL 建立儲存過程報錯MySql儲存過程
- pl/sql developer除錯儲存過程報錯處理SQLDeveloper除錯儲存過程
- GitHub學習除錯記錄Github除錯
- 錯誤記錄:apache預設網頁訪問錯誤Apache網頁
- MySQL 儲存過程和函式MySql儲存過程函式
- MySQL儲存過程 (即函式)MySql儲存過程函式
- MySQL儲存過程和函式MySql儲存過程函式
- mySql 儲存過程與函式MySql儲存過程函式
- plsql 除錯 pipelined 函式SQL除錯函式
- MongoDB的一次錯誤記錄MongoDB
- oracle plsql儲存過程除錯出錯_PLS-00361OracleSQL儲存過程除錯