mysql split 按 分割_mysql分割字符串split
在mysql數據庫中實現split函數:
代碼1:
代碼示例:
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `func_get_split_string_total`(
f_string varchar(1000),f_delimiter varchar(5)
) RETURNS int(11)
BEGIN
return 1+(length(f_string) – length(replace(f_string,f_delimiter,”)));
END$$
DELIMITER ;
代碼2:
代碼示例:
DELIMITER $$
CREATE DEFINER=`root`@`%` FUNCTION `func_get_split_string`(
f_string varchar(1000),f_delimiter varchar(5),f_order int) RETURNS varchar(255) CHARSET utf8
BEGIN
declare result varchar(255) default ”;
set result = reverse(substring_index(reverse(substring_index(f_string,f_delimiter,f_order)),f_delimiter,1));
return result;
END$$
DELIMITER ;
兩個split函數都還好用,以第二個方法為例。
在mysql中執行函數的方法:
代碼示例:
select function_name(parameter)
在創建函數時,遇到了問題。顯示錯誤:
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL,
or READS SQL DATA in its declaration and binary logging is enabled
(you *might* want to use the less safe log_bin_trust_function_creators
variable
解決方法:
1,mysql> SET GLOBAL log_bin_trust_function_creators = 1;
2,系統啟動時,加上–log-bin-trust-function-creators 參數為1
3,直接在my.ini的[mysqld]區段加上log-bin-trust-function-creators=1
小記:
使用第一種解決方法后,可以順利創建函數了,于是字符串分割函數split可以使用了。
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的mysql split 按 分割_mysql分割字符串split的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 控制器如何跳转web-inf下的项目_第
- 下一篇: mysql 优化方法_Mysql的优化方