牛骨文教育服务平台(让学习变的简单)
博文笔记

MySQL字符串按分隔符拆分函数str_split

创建时间:2014-01-23 投稿人: 浏览次数:156
CREATE FUNCTION `str_split`(
  str VARCHAR(255),
  delim VARCHAR(12),
  pos INT
) RETURNS varchar(255) CHARSET latin1
begin
  RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(str, delim, pos),LENGTH(SUBSTRING_INDEX(str,delim, pos -1)) + 1),delim,"");

end


由于这个函数里没有任何SQL语句,会提示:

Error: 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)


这里需要修改一个变量值:

set global log_bin_trust_function_creators = ON;

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。