mysql函数

MySQL字符串函数:字符串截取

寵の児 提交于 2019-12-27 10:13:12
MySQL 字符串截取函数:left(), right(), substring(), substring_index()。还有 mid(), substr()。其中,mid(), substr() 等价于 substring() 函数,substring() 的功能非常强大和灵活。 1. 字符串截取:left(str, length) mysql> select left('sqlstudy.com', 3); +-------------------------+ | left('sqlstudy.com', 3) | +-------------------------+ | sql | +-------------------------+ 2. 字符串截取:right(str, length) mysql> select right('sqlstudy.com', 3); +--------------------------+ | right('sqlstudy.com', 3) | +--------------------------+ | com | +--------------------------+ 3. 字符串截取:substring(str, pos); substring(str, pos, len) 3.1 从字符串的第 4 个字符位置开始取

mysql中floor函数的作用是什么?

痴心易碎 提交于 2019-12-27 07:27:25
需求描述 :   最近写mysql程序的时候,使用了floor函数,在此记录下该函数的作用 操作过程 : 1.使用floor函数的测试 mysql> select floor(1.23),floor(-1.23); +-------------+--------------+ | floor(1.23) | floor(-1.23) | +-------------+--------------+ | 1 | -2 | +-------------+--------------+ 1 row in set (0.00 sec) 备注:根据官方文档的提示,floor函数返回 小于等于 该值的最大整数. 示意图 : 官方文档参考 : FLOOR(X) Returns the largest integer value not greater than X. mysql> SELECT FLOOR(1.23), FLOOR(-1.23); -> 1, -2 For exact-value numeric arguments, the return value has an exact-value numeric type. For string or floating-point arguments, the return value has a floating-point type.

MySQL4:存储过程和函数

你。 提交于 2019-12-27 05:11:40
什么是存储过程 简单说,存储过程就是一条或多条SQL语句的集合,可视为批文件,但是起作用不仅限于批处理。本文主要讲解如何创建存储过程和存储函数以及变量的使用,如何调用、查看、修改、删除存储过程和存储函数等。使用的数据库和表还是之前写JDBC用的数据库和表: create database school; use school; create table student ( studentId int primary key auto_increment not null, studentName varchar(10) not null, studentAge int, studentPhone varchar(15) ) insert into student values(null,'Betty', '20', '00000000'); insert into student values(null,'Jerry', '18', '11111111'); insert into student values(null,'Betty', '21', '22222222'); insert into student values(null,'Steve', '27', '33333333'); insert into student values(null,'James', '22

mysql 创建用户自定义函数

做~自己de王妃 提交于 2019-12-27 05:08:52
为了防止分号产生的中途输出,自己定义一个 分隔符,这里仿照mysql官方的例子:使用两个美元符号 $$ 作为分割符号,下面这段代码就是创建一个自定义mysql函数的原型了,可以在这个基础上修改,这样,创建函数就不会产生很多错误了. set global log_bin_trust_function_creators = 1; -- 开启bin_log 复制 函数创建 DROP FUNCTION IF EXISTS hello; -- 删掉已经存在的 DELIMITER $$ -- 定义分隔符,必须要有,可以不是$$ CREATE FUNCTION hello( s varchar(30)) -- 多个参数用,分割 参数的类型必须是mysql列存在的类型 RETURNS VARCHAR(255) -- 指定返回值类型,如果你不确定返回文本长度,可以使用text BEGIN DECLARE str varchar(255) default 'hello '; -- 定义一个变量,可以指定默认值 SET str = concat(str,s); -- 设置改边变量的值 RETURN str; -- 返回值 END $$ -- 注意看清楚了,这个end后面有你在前面定义的分割符号 DELIMITER $$ -- 好,这里结束。 来源: https://www.cnblogs.com

Mysql自定义函数之------------This function has none of DETERMINISTIC, NO SQL解决办法

眉间皱痕 提交于 2019-12-27 05:06:39
This function has none of DETERMINISTIC, NO SQL解决办法 创建存储过程时 出错信息: 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) 原因: 这是我们开启了bin-log, 我们就必须指定我们的函数是否是 1 DETERMINISTIC 不确定的 2 NO SQL 没有SQl语句,当然也不会修改数据 3 READS SQL DATA 只是读取数据,当然也不会修改数据 4 MODIFIES SQL DATA 要修改数据 5 CONTAINS SQL 包含了SQL语句 其中在function里面,只有 DETERMINISTIC, NO SQL 和 READS SQL DATA 被支持。如果我们开启了 bin-log, 我们就必须为我们的function指定一个参数。 解决方法: SQL code mysql > show variables like '

mysql建自定义函数报错

强颜欢笑 提交于 2019-12-27 05:06:09
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法创建function时 出错信息: 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) 原因: 这是我们开启了bin-log, 我们就必须指定我们的函数是否是 1 DETERMINISTIC 不确定的 2 NO SQL 没有SQl语句,当然也不会修改数据 3 READS SQL DATA 只是读取数据,当然也不会修改数据 4 MODIFIES SQL DATA 要修改数据 5 CONTAINS SQL 包含了SQL语句 其中在function里面,只有 DETERMINISTIC, NO SQL 和 READS SQL DATA 被支持。如果我们开启了 bin-log, 我们就必须为我们的function指定一个参数。

mysql 报错之创建自定义函数

非 Y 不嫁゛ 提交于 2019-12-27 05:05:08
I experienced this error while trying to alter one of my stored procedures remotely on a master server. After some research, I ended up getting information from “ Binary Logging of Stored Programs “. From MySQL Reference in verbatim: When you create a stored function, you must declare either that it is deterministic or that it does not modify data. Otherwise, it may be unsafe for data recovery or replication. By default, for a CREATE FUNCTION statement to be accepted, at least one of DETERMINISTIC, NO SQL, or READS SQL DATA must be specified explicitly. Otherwise an error occurs: ERROR 1418

MYSQL 创建常见问题

血红的双手。 提交于 2019-12-27 05:04:24
1、创建函数时,报错: 出错信息: 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) 原因: 主从复制的两台MySQL服务器中开启了二进制日志选项log-bin,slave会从master复制数据,而一些操作,比如function所得的结果在master和slave上可能不同,所以存在潜在的安全隐患。因此,在默认情况下回阻止function的创建。 解决办法:执行 set global log_bin_trust_function_creators=TRUE; 在命令模式下 查看:show slave status\G; 是否主从不同步 来源: https://www.cnblogs.com/milanmi/p/8227661.html

Mysql创建函数出错

自闭症网瘾萝莉.ら 提交于 2019-12-27 05:03:29
mysql> delimiter // mysql> create function testfunction(id int)returns int -> begin -> declare tt int; -> set tt=0; -> select sum(total) into tt from selectinto1 b where b.id=id; -> update selectinto2 a set a.summ=tt where a.id=id; -> return 1; -> end ; -> // 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) 解决方案: mysql> set global log_bin_trust_function_creators=1; Query OK, 0 rows affected (0.00 sec) 来源: https://www.cnblogs.com

Mysql创建函数出错

不羁的心 提交于 2019-12-27 05:02:47
目前在项目中,执行创建mysql的函数出错, mysql 创建函数出错信息如下: Error Code: 1227. Access denied; you need (at least one of) the SUPER privilege(s) for this operation 首先检查创建函数的功能是否开启,检查是否开启创建功能的SQL如下: -- 查看是否开启创建函数的功能 show variables like '%func%'; -- 开启创建函数的功能 set global log_bin_trust_function_creators = 1; 执行完SQL之后发现已经开启了,随检查自己的SQL是否写错(因为SQL是别人给的,在别人环境没问题,在自己的环境就有可能)。 突然发现了确实是SQL出现问题,由于他创建的SQL有指定用户,所以导致出现问题,以下是他的SQL: DROP FUNCTION IF EXISTS `nextval`; DELIMITER ;; CREATE DEFINER=`devop`@`%` FUNCTION `nextval`(`seq_name` VARCHAR(50)) RETURNS varchar(20) CHARSET utf8 BEGIN DECLARE seq_max BIGINT(20); UPDATE